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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
GillyGils
Frequent Visitor

Optimize Running Total

Hi All,

I'm currently running the following DAX code for a Running Total based on a calculated measure. I'm looking to optimise the below DAX code?

 

VAR _Date = MAX ('Fact_Table'[Date])
VAR _Date11 = EOMONTH (_Date, -11)
VAR _Date10 = EOMONTH (_Date, -10)
VAR _Date9 = EOMONTH (_Date, -9)

 

VAR _Value11 = CALCULATE([Head Count],
FILTER(
ALL('Fact_Table'), 'Fact_Table'[Date] = _Date11)
)

VAR _Value10 = CALCULATE([Head Count],
FILTER(
ALL('Fact_Table'), 'Fact_Table'[Date] = _Date10)
)


VAR _Value9 = CALCULATE([Head Count],
FILTER(
ALL('Fact_Table'), 'Fact_Table'[Date] = _Date9)
)

 

RETURN _Value11 + _Value10 + _Value9 + [Head Count]

 

Example of results below:

GillyGils_0-1683891459508.png

 

 

Thanks.

1 ACCEPTED SOLUTION

Hi, @GillyGils 

 

You can try the following methods

Measure:

Running Head Count = SUMX(FILTER(ALL('Table'),[Date]<=SELECTEDVALUE('Table'[Date])),[Head Count])

vzhangti_0-1684823300203.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
amitchandak
Super User
Super User

@GillyGils  Use a date table and try like. Date table's date should be joined with date of your table. Use date/month from date table in visual, slicer and measures

 

CALCULATE([Head Count],filter(allselected(date),date[date] <=max(date[Date])))

or

 

Cumm Based on Date = CALCULATE([Head Count], Window(1,ABS,0,REL, ALLSELECTED('date'[date]),ORDERBY('Date'[date],ASC)))

 

or

 

CALCULATE([Head Count],filter(all(date),date[date] <=max(date[Date])))

 

or

 

Cumm Based on Date = CALCULATE([Head Count], Window(1,ABS,0,REL, all('date'[date]),ORDERBY('Date'[date],ASC)))

 

Running Total/ Cumulative:
https://www.youtube.com/watch?v=h2wsO332LUo&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=42

Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc

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

Thanks for the response.

In my fact table, its only monthly data. So I only have month end dates so which are a whole number in which ive converted to 'Date'. Is there a solution to not have a date table included?

Hi, @GillyGils 

 

You can try the following methods

Measure:

Running Head Count = SUMX(FILTER(ALL('Table'),[Date]<=SELECTEDVALUE('Table'[Date])),[Head Count])

vzhangti_0-1684823300203.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors