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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
hbgv123
Frequent Visitor

Rolling Months calculation error

Hi,

I have recently started using powerBI. So I need your help to sort my issues.

The  issue is in rolling average calculation where from raw data, i constructed a pivot. 

My expected output is based on pivot and it is basically moving average of 2months.

 

Rolling2M.JPG

 

I tried in PowerBI using a measure but values are wrong.

Hierarchy is like this Region>Priority Setting>Performance>Docket#(not used in Pivot)>Risk score. Let me know how to tackle this issue?

PowerBI_Measure.JPG

 

Raw data file in below link

Raw data file and expected output 

 

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

Hi @hbgv123 ,

 

Please try the measure.

 

Measure = 
IF (
    MAX ( Sheet1[Month] ) <> BLANK (),
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[MonthYear] ),
            CALCULATE ( AVERAGE ( Sheet1[Risk Score] ) )
        ),
        DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -2, MONTH ),
        ALLSELECTED ( 'Calendar' )
    )
)

vkkfmsft_0-1659419072087.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

7 REPLIES 7
v-kkf-msft
Community Support
Community Support

Hi @hbgv123 ,

 

Please try the measure.

 

Measure = 
IF (
    MAX ( Sheet1[Month] ) <> BLANK (),
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[MonthYear] ),
            CALCULATE ( AVERAGE ( Sheet1[Risk Score] ) )
        ),
        DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -2, MONTH ),
        ALLSELECTED ( 'Calendar' )
    )
)

vkkfmsft_0-1659419072087.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PC2790
Community Champion
Community Champion

Hey @hbgv123 ,

 

Can you try:

 

RollingAvg = AVERAGEX(DATESINPERIOD(DatesTable[Date],LASTDATE(DatesTable[Date]),-60,DAY),Sum(Table[Risk Score))

 

Sorry @PC2790 , it didnt work.

I have also attached raw data below... 

Raw data file 

PC2790
Community Champion
Community Champion

Is this you are looking for?

PC2790_0-1659115214628.png

RollingAvg =
VAR NumDays = 2
VAR _1 =
    CALCULATE (
        AVERAGEX ( VALUES ( Data[Month] ), AVERAGE ( Data[Risk Score] ) ),
        DATESINPERIOD ( Data[Month], LASTDATE ( Data[Month] ), -60, DAY )
    )
RETURN
    _1 / NumDays

Hi,

This is the output i am expecting...

Output.JPG

PC2790
Community Champion
Community Champion

Please see attached file.

I tried to come closer to your required value.

 

Thanks.. This one is closer to the required value

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!