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
stbernha
Regular Visitor

Optimize performance for running totals

Dear all,

I am struggling with optimizing the performance of a measure to calculate the running totals. Currently my DAX measure looks like below, but this measure is not performing in the way I would like. I am looking for more effective ways to calculate the running totals, for example using recursive functions. Is there anyone that can help me out with an optimized version to compute the running totals in Power BI? Many measure are depending on this one where we do even more complex analyses, so having this measure optimized will have a profound effect on the overall performance of many dashboards.

 

           CALCULATE (
                [DemandQty],
                ALL ( 'Date'[Date] ),
                'Date'[Date] <= MAX ( 'Date'[Date] ) 
            )

2 ACCEPTED SOLUTIONS

Your idea is so great @Greg_Deckler 

Hi, @stbernha 

If you want to optimize the performance of SUMX, you can refer to the following articles:

Optimizing callbacks in a SUMX iterator - SQLBI

vjianpengmsft_0-1714542424142.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

@stbernha Perhaps try:

Better RT =
  VAR _MaxDate = MAX( 'Date'[DateId] )
  VAR _Table = SUMMARIZE( ALL('BottomUp'), [DemandDateId], "_Value", SUM('BottomUp'[DemandQty]) )
  VAR _Result = SUMX( FILTER( _Table, [DemandDateId] <= _MaxDate ), [_Value] )
RETURN
  _Result

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@stbernha First, you can drop your ALL statement and that *should* be faster. Also, you can try this approach and maybe even add a SUMMARIZE to speed things up:

Better Running Total - Microsoft Fabric Community

 

Doing these kinds of calculations with CALCULATE can be problematic: CALCULATE Challenge - Round 1 - Microsoft Fabric Community


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

Thanks for your quick response. I have tried your solutions and hereby my feedback.

 

1. Using the ALLSELECTED was in my case slower, but also functionally it gives for me a different result. We have visuals were we show the running total as of total, but it might be that we have values in the past that we also want to included in the running total. Hence we used the ALL function

 

2. I have created the below measures in my data model. However, after about 20 seconds I get the message that it is too memory intensive (original measure runs for about 4 seconds). BottomUp is my fact table with an inactive relationship from BottomUp[DemandDateId] --> Date[DateId]. I already have a measure with business logic called [DemandQty] that determines the 'Value' for each demand date. The BottomUp is a table with 10.000.000 records and the date table ranges from 1-1-2022 till 31-12-2030.

DEFINE
    [Better RT] =
        VAR _MaxDate = MAX ( 'Date'[DateId] )
        VAR _Table = FILTER(ALL('BottomUp'), BottomUp[DemandDateId] <= _MaxDate)
        RETURN
            SUMX(_Table, [DemandQty])

EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Date],
    "Test", '_NewMeasures'[Better RT]
)

 

Is there something I am doing incorrectly here or other solutions that can be helpful for my use-case?

 

Kind regards,

Stefan

@stbernha Perhaps try:

Better RT =
  VAR _MaxDate = MAX( 'Date'[DateId] )
  VAR _Table = SUMMARIZE( ALL('BottomUp'), [DemandDateId], "_Value", SUM('BottomUp'[DemandQty]) )
  VAR _Result = SUMX( FILTER( _Table, [DemandDateId] <= _MaxDate ), [_Value] )
RETURN
  _Result

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Your idea is so great @Greg_Deckler 

Hi, @stbernha 

If you want to optimize the performance of SUMX, you can refer to the following articles:

Optimizing callbacks in a SUMX iterator - SQLBI

vjianpengmsft_0-1714542424142.png

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.