Forum Discussion
Rolling 3 Year Average
- 6 years ago
Hi rogerdea ,
Please try like this:
- Create a calendar table.
Date = VAR _calendar = CALENDAR ( MIN ( 'Table'[Date] ), MAX ( 'Table'[Date] ) ) RETURN ADDCOLUMNS ( _calendar, "Year", YEAR ( [Date] ) )- Create a measure.
Measure = DIVIDE ( CALCULATE ( SUM ( 'Table'[Unit] ), DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, YEAR ) ), CALCULATE ( DISTINCTCOUNT ( 'Date'[Year] ), DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, YEAR ) ) )For more details, please see the attachment.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks v-xuding-msft
I'm getting an error half way through the second part you posted: (blurred my table names for privacy)
Have i done something wrong?
Hi rogerdea ,
There is an extra parenthesis in your formula. I point it out with red pen. Please remove it to have a try.
You could download the pbix file from my answer above. It may help you a little.
- rogerdea6 years ago
Helper IV
amazing this works in my main pbx file now. However one thing which doesnt look right on your attached pbx is the 2019 average is incorrect. All others are correct. Using the same DAX this does work in my file though.
- v-xuding-msft6 years ago
Community Support
Hi rogerdea ,
Glad it works fine in your sample.😊
For the wrong result, it might be caused by date. The format of date is mm/dd/yyyy rather than dd/mm/yyyy in my sample. I don't change it to match your sample date completely. I just import it and the Desktop change it from your format to mm/dd/yyyy automatically.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.