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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Find rolling 12 month average trend

I have a custom measure named 'Measure_2' that evaluates and generates values to common unit. I have data ranging from 2018 to 2023. 

I would like to create a new DAX measure '12MonthRollingAvg' that will find the rolling average of past 12 months and another DAX measure 'Past12monthRollingAvg' that will find rolling average of 12 months a year before than current date.

I tried this DAX command but it fails.


12MonthRollingAvg =
VAR numOfMonths=12
VAR lastCurrentDate=MAX('Calendar_Month'[Calendar Month - Number])
VAR Period = DATESINPERIOD('Calendar_Month'[Calendar Month - Name], lastCurrentDate,-numOfMonths,MONTH)
VAR result = CALCULATE(
    AVERAGEX(
        VALUES('Calendar_Month'[Calendar Month - Number]), [Measure_2]),
        Period
)
Return
if ([Measure_2]>0 , result)



My desired visualization should look something like this: 
kkashiv_0-1693104125926.png

 

The blue line is for Measure '12MonthRollingAvg' and grey line is 'Past12MonthRollingAvg' 

My table for dates looks like this:

kkashiv_1-1693104296805.png

 

2 REPLIES 2
ValtteriN
Community Champion
Community Champion

Hi,

Try these kinds of structures:

12M AVG =

CALCULATE ( DIVIDE ( selectedmeasure(), 12 ), DATESBETWEEN ( 'Calendar'[Date], DATEADD ( LASTDATE ( DATEADD ( 'Calendar'[Date], -12, MONTH ) ), +1, DAY ), LASTDATE ( 'Calendar'[Date] ) ) )

PY 12M =

CALCULATE ( [12M AVG], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) )

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks for your comment. I tried out your DAX expression and tried to visualize it using spark lines. But the output isnt what I expected. I had to change your expression to accomodate my tables. This is how the DAX expression looks like now:

Rolling12Month = CALCULATE ( DIVIDE ( selectedmeasure(), 12 ), DATESBETWEEN ( 'Calendar_Month'[Calendar Month - Number], DATEADD ( LASTDATE ( DATEADD ( 'Calendar_Month'[Calendar Month - Number], -12, MONTH ) ), +1, DAY ), LASTDATE ( 'Calendar_Month'[Calendar Month - Number] ) ) )


However, the visualization with this still gives an error.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.