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
OKgo
Helper IV
Helper IV

Moving average - considering zeros and blank entries

I am looking to alter three DAX formula so that the red boxes are not calcuated (blank) and the red-stars are calcuated as 90 and 90

Hours spent. = SUM(Table46[Hrs])
Number of preceding periods. = COUNTROWS(FILTER(CALCULATETABLE(SUMMARIZE('Calendar',[Year-month],"ABCD",[Hours spent.]),DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-2),min('Calendar'[Date])-1)),[ABCD]>0))
3 months rolling average. = if([Number of preceding periods.]=2,AVERAGEX(DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-2),MAX('Calendar'[Date])),[Hours spent.]),BLANK())

PBI.png

1 ACCEPTED SOLUTION

Hi,

 

Hope this works.  Download the file from here.

 

Untitled.png

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

 

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you Ashish - I can't get the 3m average into the rows. They way you orignally had this looked really nice.

https://www.dropbox.com/sh/93zvi0qoytr1owv/AABDXX_CpkIB_EpRhLqiIBjfa?dl=0

Hi,

 

Is this your expected result?  You may download my file from here.  Here are the revised measures:

 

Number of preceding periods.. = COUNTROWS(FILTER(CALCULATETABLE(SUMMARIZE('Calendar',[Year-month],"ABCD",[Hours spent..]),DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-2),min('Calendar'[Date])-1)),[ABCD]>=0))

 

3 months rolling average.. = if(ISBLANK([Hours spent..]),BLANK(),if([Number of preceding periods..]=2,AVERAGEX(DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-2),MAX('Calendar'[Date])),[Hours spent..]),BLANK()))

 

Select the visual, click to the Format button in the visualisation pane and swith the "Show on rows" button to On.

 

Hope this helps. 

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you for sorting out the red boxes.

 

The new formula works great with zeros in the database. But not for when there are blanks. For example the 109 below should consider the blank (114 + 0 + 104) / 3 = 73

Capture.JPG

 

Can we have the first two months not populate averages like the old formula?

 

This is very education for me and thank you again for your help - if I can wire you a coffee via Paypal PM me 🙂

Hi,

 

Hope this works.  Download the file from here.

 

Untitled.png

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish - Thank you so much. Thats perfect. Loving the new months elapsed expression! Having it on the calendar table makes it all the more robust and reuseable

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors