Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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!
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.