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.
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.
- rogerdea6 years ago
Helper IV
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?
- v-xuding-msft6 years ago
Community Support
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.