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
Kurren
Helper II
Helper II

Optimize the DAX Running total

At the moment I use the following running total calculation from this tutorial:

 

 

Sales RT :=
VAR MaxDate = MAX ( 'Date'[Date] ) -- Saves the last visible date
RETURN
    CALCULATE (
        SUM([Sales Amount]),            -- Computes sales amount
        'Date'[Date] <= MaxDate,   -- Where date is before the last visible date
        ALLSELECTED ( Date )               -- Removes any other filters from Date
    )

 

 

I have a large number of transactions. Two questions:

 

  1. As far as I can tell, for each transaction this recomputes the sum of all transactions with the date less than or equal to the current transaction. If this is correct, then am I correct in saying that this runs in O(n^2) complexity?
  2. If so, then is there a way to just add the current transaction's total onto the previous running total so that this runs in linear, O(n), complexity? The caveat is that all slicers must be respected (which is why I use ALLSELECTED above)

Any help would be greatly appreciated.

 

2 REPLIES 2
Kurren
Helper II
Helper II

Thanks @Icey . A shame that the running total must be so innefficient without any workaround.

 

Why don't I need ALLSELECTED?

Icey
Community Support
Community Support

Hi @Kurren ,

 

1. As far as I can tell, for each transaction this recomputes the sum of all transactions with the date less than or equal to the current transaction. If this is correct, then am I correct in saying that this runs in O(n^2) complexity?

 

Yes.

 

2. If so, then is there a way to just add the current transaction's total onto the previous running total so that this runs in linear, O(n), complexity? The caveat is that all slicers must be respected (which is why I use ALLSELECTED above)

 

No. To my knowledge, this is by design.

 

In addition, in your scenario, ALLSELECTED is not needed.

Sales RT :=
VAR MaxDate = MAX ( 'Date'[Date] ) -- Saves the last visible date
RETURN
    CALCULATE (
        SUM([Sales Amount]),            -- Computes sales amount
        'Date'[Date] <= MaxDate   -- Where date is before the last visible date
    )

 

 

Best Regards,

Icey

 

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