Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JasonCou
Frequent Visitor

Rate of change (Trend %) per Week

Hey Everyone,

I'm trying to get a colum in a Power BI table that shows a calculated average improvement based on weekly metric results.

 

The raw data looks likes this.

JasonCou_0-1713283338445.png

 

My idea is to calculate the average metric per week using it's weight with a dax formula. Like this:

 

 

AVG Metric = 
 DIVIDE(
    SUMX(
        RAW_METRICS2,
        RAW_METRICS2[Metric] * RAW_METRICS2[Weight]
    ),
    SUM(RAW_METRICS2[Weight])
 )

 

 

 

Then, somehow calculate the "improvement" of the current week compared to the past week the trend using this formula:

 

 

week_trend =  (current week AVG metric) - (past week AVG metric)

 

 

 

And for all selected weeks between the selected dates (using slicer) get the average improvement.

 

This table roughly sumarizes the improvement week over week of selected data. 

JasonCou_2-1713284345483.png

 

This is what i want to see in the Power BI table on my report. A

JasonCou_3-1713285156952.png

 

 

 

 

1 ACCEPTED SOLUTION
v-yilong-msft
Community Support
Community Support

Hi @JasonCou ,

I create a table as you mentioned.

vyilongmsft_0-1713768392073.png

Then I a measure , here is the DAX code.

Improvement =
VAR _currentPerson =
    SELECTEDVALUE ( RAW_METRICS2[Person] )
VAR _currentFW =
    MAX ( 'RAW_METRICS2'[FW] )
VAR _PreviousFW =
    CALCULATE (
        MAX ( 'RAW_METRICS2'[FW] ),
        FILTER ( ALLSELECTED ( RAW_METRICS2 ), 'RAW_METRICS2'[FW] < _currentFW )
    )
VAR _vtable =
    SUMMARIZE (
        ALLSELECTED ( 'RAW_METRICS2' ),
        'RAW_METRICS2'[Person],
        'RAW_METRICS2'[FW],
        "_Metric", 'RAW_METRICS2'[AVG Metric]
    )
VAR _vtable2 =
    ADDCOLUMNS (
        _vtable,
        "_LastMetric",
            MAXX (
                FILTER ( _vtable, [Person] = _currentPerson && [FW] = _PreviousFW ),
                [_Metric]
            )
    )
RETURN
    IF (
        MAXX (
            FILTER ( _vtable2, [Person] = _currentPerson && [FW] = _currentFW ),
            [_LastMetric]
        )
            <> BLANK (),
        [AVG Metric]
            - MAXX (
                FILTER ( _vtable2, [Person] = _currentPerson && [FW] = _currentFW ),
                [_LastMetric]
            ),
        0
    )

vyilongmsft_1-1713769248401.png

Finally you will get what you want.

vyilongmsft_2-1713769382249.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yilong-msft
Community Support
Community Support

Hi @JasonCou ,

I create a table as you mentioned.

vyilongmsft_0-1713768392073.png

Then I a measure , here is the DAX code.

Improvement =
VAR _currentPerson =
    SELECTEDVALUE ( RAW_METRICS2[Person] )
VAR _currentFW =
    MAX ( 'RAW_METRICS2'[FW] )
VAR _PreviousFW =
    CALCULATE (
        MAX ( 'RAW_METRICS2'[FW] ),
        FILTER ( ALLSELECTED ( RAW_METRICS2 ), 'RAW_METRICS2'[FW] < _currentFW )
    )
VAR _vtable =
    SUMMARIZE (
        ALLSELECTED ( 'RAW_METRICS2' ),
        'RAW_METRICS2'[Person],
        'RAW_METRICS2'[FW],
        "_Metric", 'RAW_METRICS2'[AVG Metric]
    )
VAR _vtable2 =
    ADDCOLUMNS (
        _vtable,
        "_LastMetric",
            MAXX (
                FILTER ( _vtable, [Person] = _currentPerson && [FW] = _PreviousFW ),
                [_Metric]
            )
    )
RETURN
    IF (
        MAXX (
            FILTER ( _vtable2, [Person] = _currentPerson && [FW] = _currentFW ),
            [_LastMetric]
        )
            <> BLANK (),
        [AVG Metric]
            - MAXX (
                FILTER ( _vtable2, [Person] = _currentPerson && [FW] = _currentFW ),
                [_LastMetric]
            ),
        0
    )

vyilongmsft_1-1713769248401.png

Finally you will get what you want.

vyilongmsft_2-1713769382249.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ExcelMonke
Responsive Resident
Responsive Resident

If you remove the FW column it may give you your intended result

Hey thank you, but what I need is the AVG improvement wow, so I can't remove the FW colum from the raw data. I do, though, not have it on the Powe BI table, but then the improvement is not calculated WOW

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.