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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
renegar
Microsoft Employee
Microsoft Employee

A more efficient running total ?

I've calculating a running total based on 4 conditions/filters, the calculated column works on a small scale, but when I used in larger data set (2M rows) it never finished recalculating. I'm wondering if there is a more efficient way. I've read most posts on Running totals, and avoided using calculate vs sumx due to context transition but still. 

 

Table structure as follows

 

QtySKUStartEndIDResult
10A5/1/20196/1/2019A10
-10A5/2/20196/1/2019A0
40A5/2/20196/1/2019B40

 

Here is my Calculated Column

=
VAR start1 = Table1[Start]
VAR end1 = Table1[End]
VAR sku1 = Table1[SKU]
VAR subid1 = Table1[ID]
RETURN
SUMX (
FILTER (
Table1,
[Start] <= start1
&& [End] = end1
&& [SKU] = sku1
&& [ID] = subid1
),
Table1[Qty]
)

 

 

 

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@renegar ,

 

SUMX() is an iterator function so it will traverse the whole table, you can use SUM() function instead as below to improve the performance.

Result =
VAR start1 = Table1[Start]
VAR end1 = Table1[End]
VAR sku1 = Table1[SKU]
VAR subid1 = Table1[ID]
RETURN
    CALCULATE (
        SUM ( Table1[Qty] ),
        FILTER (
            Table1,
            [Start] <= start1
                && [End] = end1
                && [SKU] = sku1
                && [ID] = subid1
        )
    )

Community Support Team _ Jimmy Tao

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
v-yuta-msft
Community Support
Community Support

@renegar ,

 

SUMX() is an iterator function so it will traverse the whole table, you can use SUM() function instead as below to improve the performance.

Result =
VAR start1 = Table1[Start]
VAR end1 = Table1[End]
VAR sku1 = Table1[SKU]
VAR subid1 = Table1[ID]
RETURN
    CALCULATE (
        SUM ( Table1[Qty] ),
        FILTER (
            Table1,
            [Start] <= start1
                && [End] = end1
                && [SKU] = sku1
                && [ID] = subid1
        )
    )

Community Support Team _ Jimmy Tao

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

hnguy71
Memorable Member
Memorable Member

Hi @renegar ,

Instead of using a calculated column, perhaps a measure may suffice? For example, a simple cumculative total measure like this would give you a similar result (for the year):

RunningTotal = CALCULATE(SUM(YOUR_TABLE[Qty]), DATESYTD(YOUR_TABLE[Start]))

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
renegar
Microsoft Employee
Microsoft Employee

Unfortunatetly I can't but, I found that if I do that "[End]=end1" comparison in text (rather than date) it runs pretty fast. Go figure...

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.