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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jovendeluna21
Helper IV
Helper IV

Dynamic Rolling Monthly Average on Line Chart

Hi, 

I just want to request any help to have a dynamic rolling monthly average for a line chart. I don't know if there's any problem in the DAX formula I have created because only 1 Month shows correct number. When I try to change the parameter, the number is not correct.

I have uploaded here the copy of the pbix.

https://drive.google.com/file/d/1bVFRkAEcSFnmbleYbfqqwi3zL0Y8FVAY/view?usp=sharing

Thank you!

 

dyna.PNG

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @jovendeluna21 ;

Please try it.

Rolling N Months2 = 
var _table=
    SUMMARIZE(FILTER(ALL('Raw Data'),[Date]<=MAX('Raw Data'[Date])&&[Date]>EOMONTH(MAX('Raw Data'[Date]),-[Parameter Value])),[Date],"1",  DIVIDE(
        SUM ( 'Raw Data'[SumProd] ) ,SUM ( 'Raw Data'[TOTAL_SPEND] )))
var _count=
    CALCULATE (
        DISTINCTCOUNT ( 'Raw Data'[Date] ),
        DATESINPERIOD ( 'Raw Data'[Date],MAX('Raw Data'[Date]), - [Parameter Value], MONTH ),
        ALL ( 'Raw Data' ))
return DIVIDE(SUMX(_table,[1]),_count)

The final output is shown below:

vyalanwumsft_0-1634177835663.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-yalanwu-msft
Community Support
Community Support

Hi, @jovendeluna21 ;

Please try it.

Rolling N Months2 = 
var _table=
    SUMMARIZE(FILTER(ALL('Raw Data'),[Date]<=MAX('Raw Data'[Date])&&[Date]>EOMONTH(MAX('Raw Data'[Date]),-[Parameter Value])),[Date],"1",  DIVIDE(
        SUM ( 'Raw Data'[SumProd] ) ,SUM ( 'Raw Data'[TOTAL_SPEND] )))
var _count=
    CALCULATE (
        DISTINCTCOUNT ( 'Raw Data'[Date] ),
        DATESINPERIOD ( 'Raw Data'[Date],MAX('Raw Data'[Date]), - [Parameter Value], MONTH ),
        ALL ( 'Raw Data' ))
return DIVIDE(SUMX(_table,[1]),_count)

The final output is shown below:

vyalanwumsft_0-1634177835663.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @jovendeluna21 ;

You could try it.

Rolling N Months = 
DIVIDE (
    CALCULATE (
        SUM ( 'Raw Data'[SumProd] ) / SUM ( 'Raw Data'[TOTAL_SPEND] ),
        DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), - [Parameter Value], MONTH )
    ),
    CALCULATE (
        DISTINCTCOUNT ( 'Raw Data'[Date] ),
        DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), - [Parameter Value], MONTH ),
        ALL ( 'Raw Data' )
    )
)

The final output is shown below:

vyalanwumsft_0-1634114514980.pngvyalanwumsft_1-1634114522901.png

If not ringht ,can you share the output you want?

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, @v-yalanwu-msft , thank you for your response. This is the output I want and I tried in excel. For example, if the dynamic parameter is "3" months rolling average, it should average the last 3 months including the current month such as below. For example "01-Jun-21" rolling N months is the average of April, May and Jun, then ""01-May-21" is the average of Mar, Apr and May. then so on.

 

SAM.PNG

Hi, @jovendeluna21 ;

It may be Rolling N Months2 in my PBIX,

Rolling N Months2 = 
var _table=SUMMARIZE(FILTER(ALL('Raw Data'),[Date]<=MAX('Date'[Date])&&[Date]>=EOMONTH(MAX('Date'[Date]),-[Parameter Value])),[Date],"1",  DIVIDE(
        SUM ( 'Raw Data'[SumProd] ) ,SUM ( 'Raw Data'[TOTAL_SPEND] ))
       )
    var _b=
DIVIDE (
    SUMX(_table,[1]),
    CALCULATE (
        DISTINCTCOUNT ( 'Raw Data'[Date] ),
        DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), - [Parameter Value], MONTH ),
        ALL ( 'Raw Data' )
    )
)
return IF(MAX([Date])<=MAX('Date'[Date])&&MAX([Date])>=EOMONTH(MAX('Date'[Date]),-[Parameter Value]),_b)

 The final output is shown below:

vyalanwumsft_0-1634119785730.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Is it possible that every month has a rolling average? Just like the table belowsam 2.PNG

because when I tried to use the one you created, with 3 as parameter, only the last data point which is 01-Jun-21 has the Rolling N Months2 value

sam 3.PNG

amitchandak
Super User
Super User

@jovendeluna21 , With a date table try like

 

Rolling N Months =
divide( CALCULATE(
SUM('Raw Data'[SumProd])/SUM('Raw Data'[TOTAL_SPEND]),
DATESINPERIOD('Date'[Date], max('Date'[Date]),-[Parameter Value],MONTH)
)
,
CALCULATE(
DISTINCTCOUNT('Raw Data'[Date]),
DATESINPERIOD('Date'[Date], MAx('Date'[Date]), -[Parameter Value], MONTH)
)
)

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi, @amitchandak , thank you for your response! I have tried to do this, however when I try 3 in the parameter, only 1 point is showing which is the latest month only. I'm aiming that every month will have rolling average as well. Is that possible? Thank you!

 

d.PNG

@jovendeluna21 , Please check if the attached file can help

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi, @amitchandak , seems like the numbers are erratic.

 

fd.PNG

sds.PNG

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors