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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
jovendeluna21
Helper IV
Helper IV

Dynamic Rolling Average & Sum based on Slicer Selection

Hello,

Any idea  on how a dynamic rolling average and spend be dynamic based on slicers?

I just noticed that the numbers do not change when I use different slicers such as World Area, Commodity, etc.

I have attached here the pbi file.

https://drive.google.com/file/d/1XhnWQcAFO1i15tz-Ukna2TjdFL0UKT_8/view?usp=sharing

 

Herewith my formula:

AVE. EXH DAYS (Rolling N Months) =
var _table=
SUMMARIZE(FILTER(ALL('AVE PAYMENT TERMS RAW DATA'),[DATE]<=MAX('AVE PAYMENT TERMS RAW DATA'[DATE])&&[DATE]>EOMONTH(MAX('AVE PAYMENT TERMS RAW DATA'[DATE]),-[Parameter Value])),[DATE],"1", DIVIDE(
SUM ('AVE PAYMENT TERMS RAW DATA'[SUMPROD EXH247A]),SUM ('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND])))
var _count=
CALCULATE (
DISTINCTCOUNT ( 'AVE PAYMENT TERMS RAW DATA'[DATE] ),
DATESINPERIOD ( 'AVE PAYMENT TERMS RAW DATA'[DATE],MAX('AVE PAYMENT TERMS RAW DATA'[DATE]), - [Parameter Value], MONTH ),
ALL ( 'AVE PAYMENT TERMS RAW DATA' ))
return DIVIDE(SUMX(_table,[1]),_count)
 
SPEND (Rolling N Months) =
var _table=
SUMMARIZE(FILTER(ALL('AVE PAYMENT TERMS RAW DATA'),[DATE]<=MAX('AVE PAYMENT TERMS RAW DATA'[DATE])&&[DATE]>EOMONTH(MAX('AVE PAYMENT TERMS RAW DATA'[DATE]),-[Parameter Value])),[DATE],"1", CALCULATE(
SUM ( 'AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND] )))
var _count=
CALCULATE (
DISTINCTCOUNT ( 'AVE PAYMENT TERMS RAW DATA'[DATE] ),
DATESINPERIOD ( 'AVE PAYMENT TERMS RAW DATA'[DATE],MAX('AVE PAYMENT TERMS RAW DATA'[DATE]), - [Parameter Value], MONTH ),
ALL ( 'AVE PAYMENT TERMS RAW DATA' ))
return SUMX(_table,[1])
 
rolling.PNG
It's not required but is it possible to use two parameters in a measure? Because I want also to have a dynamic last N months. For example, I want to see only last 6 months based on selected date.
 
Thank you!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@jovendeluna21 , With help from the date table, measures like example measure should help

 

Rolling 30 = calculate(AverageX(Values('Date'[Date]),CALCULATE(sum(Sales[Sales Amount]))),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-30,DAY))

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

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@jovendeluna21 , With help from the date table, measures like example measure should help

 

Rolling 30 = calculate(AverageX(Values('Date'[Date]),CALCULATE(sum(Sales[Sales Amount]))),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-30,DAY))

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

tried this one but giving me incorrect number

Rolling N = calculate(AverageX(Values('Date'[Date]),CALCULATE(sum('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND]))),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-[Parameter Value],MONTH))

@jovendeluna21 , For Days Avg

Rolling N = calculate(AverageX(Values('Date'[Date]),CALCULATE(sum('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND]))),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1* [Parameter Value],MONTH))

 

 

For Months Avg// Sum till month Avg post that


Rolling N = calculate(AverageX(Values('Date'[Month Year]),CALCULATE(sum('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND]))),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1* [Parameter Value],MONTH))

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

@jovendeluna21 , For Days Avg

Rolling N = calculate(AverageX(Values('Date'[Date]),CALCULATE(sum('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND]))),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1* [Parameter Value],MONTH))

 

 

For Months Avg// Sum till month Avg post that


Rolling N = calculate(AverageX(Values('Date'[Month Year]),CALCULATE(sum('AVE PAYMENT TERMS RAW DATA'[TOTAL_SPEND]))),DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-1* [Parameter Value],MONTH))

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

roll.PNG

 

Still wrong, actually the numbers I have are already correct using my previous DAX measures, it's just that when I use other slicers the numbers do not change, which should be.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.