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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply

Leave blank 3 month rolling average if not all 3 months have data

Hello! I have a rolling average formula as follows:

 

 

3mo. rolling average = CALCULATE( SUMX( VALUES( Dates[Calendar Month] ), [SS]) , DATESINPERIOD( Dates[Calendar Month], MAX( Dates[Calendar Month] ), +2, MONTH ) ) /3

 

 

I want to put it into a chart and compare it to the actuals.

 

For the first two months and last two months, however, the numbers go all squiffy because I don't have the previous 2 months / next 2 months data.  So on my chart I have some ugly lines at start and at end (cirlced in red here):

 

Untitled.png

I'd thought to create some sort of formula along the lines of an if blank, but not sure how to do it.  

 

Any thoughts?

1 ACCEPTED SOLUTION
dedelman_clng
Community Champion
Community Champion

Hi @dapperscavenger  - something like this might work

 

3m RA = var __myDate = MAX(Dates[Calendar Month])
var __MaxDt = CALCULATE(MAX(Dates[Calendar Month]), ALL(Dates)) 
var __MinDt = CALCULATE(MIN(Dates[Calendar Month]), ALL(Dates)) 
RETURN 
IF ( OR(
      ABS(DATEDIFF (__myDate, __MaxDt, MONTH)) <= 2, 
        ABS(DATEDIFF (__myDate, __MinDt, MONTH)) <= 2
       ), 
       BLANK(), 
       [Your Calculation]
)

 

2020-08-20 10_47_09-Untitled - Power BI Desktop.png

 

Hope this helps

David

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@dapperscavenger , not very clear try

 

Rolling 2 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-2,MONTH))

 

Rolling 2 till last 2 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-2,month)),-2,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
dedelman_clng
Community Champion
Community Champion

Hi @dapperscavenger  - something like this might work

 

3m RA = var __myDate = MAX(Dates[Calendar Month])
var __MaxDt = CALCULATE(MAX(Dates[Calendar Month]), ALL(Dates)) 
var __MinDt = CALCULATE(MIN(Dates[Calendar Month]), ALL(Dates)) 
RETURN 
IF ( OR(
      ABS(DATEDIFF (__myDate, __MaxDt, MONTH)) <= 2, 
        ABS(DATEDIFF (__myDate, __MinDt, MONTH)) <= 2
       ), 
       BLANK(), 
       [Your Calculation]
)

 

2020-08-20 10_47_09-Untitled - Power BI Desktop.png

 

Hope this helps

David

Hi David,

 

This worked great, thank you!

 

I adjusted the formula ever so slightly so that it was <=1 instead of <=2 .  Then it was exactly what I needed 🙂

3mo RA = var __myDate = MAX(Dates[Calendar Month]])
var __MaxDt = CALCULATE(MAX(Dates[Calendar Month]), ALL(Dates)) 
var __MinDt = CALCULATE(MIN(Dates[Calendar Month]), ALL(Dates)) 
RETURN 
IF ( OR(
      ABS(DATEDIFF (__myDate, __MaxDt, MONTH)) <= 1, 
        ABS(DATEDIFF (__myDate, __MinDt, MONTH)) <= 1
       ), 
       BLANK(), 
       [my calculation]
)

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.