Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a rolling average for sales data of the last 12 months and a Date slicer. The rolling Avg DAX is from Quick measures "Rolling Average".
The problem is that when using the slicer (Lets say I enter 2016), the Rolling average is ignoring the dates from the previous year (2015).
I want it to display the months of 2016, but the rolling avgerage should still be calculated using data from 12 months back.
Added a PBIX File to download with my example below.
Code with Rolling Avg Today:
Solved! Go to Solution.
Hey,
based on the pbix you provided, I added a calculated column to your calendar table, this column contains an index value for each month across the complete calendar:
month running index = var DateFirst = MIN('Calendar'[Date]) var YearFirst = YEAR(DateFirst) return (YEAR('Calendar'[Date])-YearFirst)*12 + MONTH('Calendar'[Date])
Using this kind of index columns allows to easily navigate through all kind of tables, and personally I think it makes filtering much more readable.
After this I created a measure like so:
_Sales rolling average = var theLastMonthIndex = CALCULATE(MAX('Calendar'[month running index])) var theLastTwelveMonths = SUMMARIZE( SELECTCOLUMNS( FILTER( ALL('Calendar') ,'Calendar'[month running index] >= theLastMonthIndex - 12 && 'Calendar'[month running index] <= theLastMonthIndex - 1 ) ,"MonthIndex" ,'Calendar'[month running index] ) ,[MonthIndex] ) return CALCULATE( AVERAGEX( theLastTwelveMonths ,CALCULATE(SUM('Salestable'[Sales])) ) ,ALL('Calendar') ,theLastTwelveMonths )
Using this measure I can create a report that looks like this:
I'm not sure, if you are familiar with this site: https://www.daxpatterns.com/time-patterns/
If not I think it's a great read.
Hopefully this provides what you are looking for.
Regards,
Tom
Hey,
based on the pbix you provided, I added a calculated column to your calendar table, this column contains an index value for each month across the complete calendar:
month running index = var DateFirst = MIN('Calendar'[Date]) var YearFirst = YEAR(DateFirst) return (YEAR('Calendar'[Date])-YearFirst)*12 + MONTH('Calendar'[Date])
Using this kind of index columns allows to easily navigate through all kind of tables, and personally I think it makes filtering much more readable.
After this I created a measure like so:
_Sales rolling average = var theLastMonthIndex = CALCULATE(MAX('Calendar'[month running index])) var theLastTwelveMonths = SUMMARIZE( SELECTCOLUMNS( FILTER( ALL('Calendar') ,'Calendar'[month running index] >= theLastMonthIndex - 12 && 'Calendar'[month running index] <= theLastMonthIndex - 1 ) ,"MonthIndex" ,'Calendar'[month running index] ) ,[MonthIndex] ) return CALCULATE( AVERAGEX( theLastTwelveMonths ,CALCULATE(SUM('Salestable'[Sales])) ) ,ALL('Calendar') ,theLastTwelveMonths )
Using this measure I can create a report that looks like this:
I'm not sure, if you are familiar with this site: https://www.daxpatterns.com/time-patterns/
If not I think it's a great read.
Hopefully this provides what you are looking for.
Regards,
Tom
@TomMartens , your solution is really clever and works like a charm.
You just saved my day, my week, my year and you are from today my number one hero!
If you have any blog or similar, do let know and I will follow you!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
85 | |
67 | |
59 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |