<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: a more efficient way to do running totals: why is DAX not efficient at doing this? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2873137#M92800</link>
    <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, I can also show you a screenshot from Power BI itself. &lt;STRONG&gt;The run times are just like the ones that come from DAX Studio.&lt;/STRONG&gt; But I did this in DS because I could run this without the visual's&amp;nbsp; rendering overhead and could benchmark the measures via DS native tools with the automation of the number of runs to get means and standard deviations. It just so happens that it's not necessary at all to be able to access the row before and the brute-force approach is more than good enough to make your code as fast as lightning! That's good news, I guess? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One remark, though. My computer is a beast (Alienware R17) and this obviously had an impact on the numbers. &lt;STRONG&gt;But the relative run times should still stand on any computer, of course.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please send me a link to your file so that I can see what will happen on my machine. By the way, it's a pity you didn't unfold the "Table" entry in Performance Analyzer. Because of this we can't see the breakdown of run times &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers.&lt;/P&gt;</description>
    <pubDate>Sun, 30 Oct 2022 16:22:52 GMT</pubDate>
    <dc:creator>daXtreme</dc:creator>
    <dc:date>2022-10-30T16:22:52Z</dc:date>
    <item>
      <title>a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2869480#M92551</link>
      <description>&lt;P&gt;A common problem that recurs in forums is the calculation of running totals.&amp;nbsp; There are many videos and posts that provide solutions for the particular use case requested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general the answer works like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;there's a table that has one column containing a Value, another with a Rank (the order of the row in the table).&amp;nbsp; Often the Rank is a date, or datetime.&lt;/LI&gt;&lt;LI&gt;use a calculated column to provide a row context or use an iterator function in a measure&lt;/LI&gt;&lt;LI&gt;use calculate to sum all values up to the current row by acting on the table of Values that has been filtered so that it only include rows with Ranks before the current row in the row context.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I can't be alone in thinking this is a horribly inefficient way of doing things.&amp;nbsp; In the 100th row of the table, the SUM function is adding up 100 Values.&amp;nbsp; By the time we get to the 10,000th row, there are 10,000 rows to add up.&amp;nbsp; For big tables, processing takes hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Surrely we just need to find the value of the Running Total in the PREVIOUS row for the row being currently calculated and add it to the Value in current row.&amp;nbsp; The number of calculations scales linearly with table size, rather than exponentially.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've use R before for data analysis and the widely-used DPLYR package by Hadley et al.&amp;nbsp; For a table in DPLYR you can access a value from the row before or the row after using the functions 'Lag' and 'Lead'.&amp;nbsp; &amp;nbsp;I'm no expert in SQL, but there's a similar LEAD() function that allows code to access rows offset from the current row.&amp;nbsp; Similar functions would surely be useful in DAX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd appreciate someone from Microsoft posting a sensible reply to this.&amp;nbsp; Are we going to get a function that in DAX that returns the value of a column in the NEXT or PREVIOUS row (within a row context)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 03:18:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2869480#M92551</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-28T03:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2869785#M92565</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not from M$ but... you are wrong thinking that this calculation is inefficient &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It's very efficient even though it's a brute-force approach. But Power BI and DAX work mostly like that, using a brute-force approach. There are 2 engines that do calculations in PBI: the Storage Engine and Formula Engine. The Storage Engine is multithreaded, simple and extremely fast. If you write your DAX to mostly use this engine, the brute-force approach will be extremely fast. Please read about the two engines. There are also vids on YT by Marco and Alberto that dive deeper into these topics. Also, it's worth reading their book (if you haven't yet)...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, there is a function (unofficial yet but is coming) called "offset." One can use it even now in DAX, even though there's no intellisense for it yet. It's like the "offset" function in Excel and "lag," or "lead," in SQL.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 06:50:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2869785#M92565</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-28T06:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2871860#M92716</link>
      <description>&lt;P&gt;Thanks for the reply daXtreme.&amp;nbsp; I think we're agreeing with each other.&amp;nbsp; You call it a 'brute force' approach, while I used the word 'inefficient'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The algorithm that we currently have to use to calculate running totals is without any doubt inefficient.&amp;nbsp; If you were doing a running total with pen and paper, you'd add the amount in the current row to the running total in the previous row and write the result in the running total column.&amp;nbsp; If the 'offset' function you mentioned enables a similar process in DAX then it's good.&amp;nbsp; That was my point.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 01:16:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2871860#M92716</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-29T01:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2871864#M92717</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, indeed, "offset" is supposed to make such calculations easier for the end user/coder and - hopefully! - faster. However, the current approach is not inefficient because the engine could be, or is, smart enough to know that, for each cell, it has to add one more number to what it has already calculated. To know for sure how it's done you'll have to read the physical (and logical) DAX plan (similar to what SQL produces when it wants to exec a query). Even though the plan can easily&amp;nbsp;&lt;SPAN&gt;be obtained from DAX Studio, it takes a bit of knowledge and experience to read it correctly and thus know what's going on under the hood.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 01:46:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2871864#M92717</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-29T01:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872147#M92729</link>
      <description>&lt;P&gt;I'm a scientist by training, so I believe the results of experiments over the predictions of theories.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I decided to test your hypothesis that PBI would be able to run the calculations for a cumulative sum efficiently.&amp;nbsp; To do this I set up a simple table in Excel.&amp;nbsp; The first column is the row number.&amp;nbsp; The second value column is the series of numbers 1 to 10,000.&amp;nbsp; The cumulative sum of the value column should then be the set of triangular numbers: {1,3,6,10,15...}.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a calculate column for the cumulative sum, for which of course there's a row context.&amp;nbsp; I timed the column calculate using my phone and I got a little over 19 seconds.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code for the calculated column was this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;**bleep** sum = &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;currRow&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;'10,000 rows'&lt;/SPAN&gt;&lt;SPAN&gt;[row number]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'10,000 rows'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'10,000 rows'&lt;/SPAN&gt;&lt;SPAN&gt;[value]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'10,000 rows'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;'10,000 rows'&lt;/SPAN&gt;&lt;SPAN&gt;[row number]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= &lt;/SPAN&gt;&lt;SPAN&gt;currRow&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;// **bleep** sum for 10,000 rows&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then tried using a measure and the performance analyzer.&amp;nbsp; I set up a table visual with all 10,000 rows showing.&amp;nbsp; I then dragged in a measure that performs the cumulative sum:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;**bleep** sum measure = &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; currRow = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;('10,000 rows'[row number])&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt;('10,000 rows'[value]),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; '10,000 rows'[row number] &amp;lt;= currRow&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;// **bleep** sum for 10,000 rows&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&lt;SPAN&gt;The table calculated the **bleep** sum as the triangle numbers correctly, as you can see in this screenshot:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&lt;SPAN&gt;The time taken for the table to calculate was 19, 711 ms, similar to the number for the calculated column.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&lt;SPAN&gt;Finally I tried copying a formula in Excel over the table with a column called **bleep** sum.&amp;nbsp; Each new row's **bleep** sum value is the sum of the value in that row and the previous row's **bleep** sum.&amp;nbsp; Copying that cell formula over a table of 100,000 rows was finished faster than I could time it.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#333333"&gt;&lt;SPAN&gt;Clearly Excel outperforms Power BI because it's algorithm for computing the running total is efficient.&amp;nbsp; For my application I have 100,000s of rows.&amp;nbsp; The other day a similar computation (actually a moving average) took a little less than 6 hours.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 29 Oct 2022 10:49:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872147#M92729</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-29T10:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872149#M92730</link>
      <description>&lt;P&gt;apologies for everyone reading this - it seems the first 3 letters of the word 'cumulative' have been picked up by the sensors and replaced by **bleep**&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 10:52:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872149#M92730</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-29T10:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872309#M92744</link>
      <description>&lt;P&gt;Hi there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, I'm a math'cian by edu and BI Dev (or something similar) by prof &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Hi there. Your code is not written efficiently. You should &lt;STRONG&gt;never&lt;/STRONG&gt; put a full table as a filter in CALCULATE. This puts a lot of burden on the engine and hence the run times are awful. I'll run your tests with efficient code for the "ineficcient" algorithm and see what happens &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bear with me...&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 14:21:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872309#M92744</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-29T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872344#M92746</link>
      <description>&lt;P&gt;Here are the findings.&lt;/P&gt;
&lt;P&gt;Here's the query that I was benchmarking in DAX Studio.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;DEFINE 


MEASURE 'Test Data'[Running Total] = 
var CurrentPoint = MAX( 'Test Data'[Point] )
var Output = 
    CALCULATE(
        SUMX(
            'Test Data',
            'Test Data'[Point]
        ),
        'Test Data'[Point] &amp;lt;= CurrentPoint
    )
return
    Output


MEASURE 'Test Data'[Running Total 2] = 
SUMX(
    ALL( 'Test Data' ),
    'Test Data'[Point] * ('Test Data'[Point] &amp;lt;= MAX( 'Test Data'[Point] ))
)


MEASURE 'Test Data'[Running Total 3] = 
var CurrentPoint = MAX( 'Test Data'[Point] )
var PrecomputedRTForAllPoints = 
    ADDCOLUMNS(
        'Test Data',
        "@RT",
            var CurrentPoint = 'Test Data'[Point]
            return
                SUMX(
                    FILTER(
                        'Test Data',
                        'Test Data'[Point] &amp;lt;= CurrentPoint
                    ),
                    'Test Data'[Point]
                )
    )
var Output = 
    MAXX(
        FILTER(
            PrecomputedRTForAllPoints,
            'Test Data'[Point] = CurrentPoint
        ),
        [@RT]
    )
return
    Output
    
    
MEASURE 'Test Data'[Running Total 4] = 
var GeneratedRTForAllPoints = 
    GENERATE(
        'Test Data',
        var CurrentPoint = 'Test Data'[Point]
        var RT = 
            SUMX(
                FILTER(
                    'Test Data',
                    'Test Data'[Point] &amp;lt;= CurrentPoint
                ),
                'Test Data'[Point]
            )
        return
            row( "@RT", RT )
    )
var CurrentPoint = MAX( 'Test Data'[Point] )
var Output =
    MAXX(
        FILTER(
            GeneratedRTForAllPoints,
            'Test Data'[Point] = CurrentPoint
        ),
        [@RT]
    )
return
    Output


EVALUATE
SUMMARIZECOLUMNS(
    'Test Data'[Point]
,    "Running Total", [Running Total]
//,    "Running Total 2", [Running Total 2]
//,    "Running Total 3", [Running Total 3]
//,    "Running Total 4", [Running Total 4]
)
ORDER BY
    'Test Data'[Point] ASC&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first (naive) measure took&amp;nbsp;&lt;STRONG&gt;17 s&lt;/STRONG&gt; on average.&lt;/P&gt;
&lt;P&gt;The second, also brute-force, measure took &lt;STRONG&gt;10 sec&lt;/STRONG&gt; on average.&lt;/P&gt;
&lt;P&gt;The third one, also brute-force, took... well, between &lt;STRONG&gt;25 and 32 MILISECONDS&lt;/STRONG&gt; on average.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The last one, also brute-force, took... 25 miliseconds on average and this was consistently stable for the warm and cold cache.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find the results in the pictures below.&lt;/P&gt;
&lt;DIV id="tinyMceEditor_772d05b8981476daXtreme_4" class=""&gt;
&lt;P&gt;&lt;FONT size="6" color="#0000FF"&gt;&lt;STRONG&gt;Well, does this blow your mind yet? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;
&lt;P&gt;For the 4th measure (the clear winner):&lt;/P&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;For the 3rd measure:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;For the 1st measure:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Sadly, this editor messed up my pictures and my code. So the 3rd measure is not shown but it was 7 secs on average as mentioned above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Once again, a brute-force method can be as fast as 25 miliseconds on such a dataset if you write your DAX the right way.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 15:21:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872344#M92746</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-29T15:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872921#M92789</link>
      <description>&lt;P&gt;Thanks for you work on this DaXtreme!&amp;nbsp; I'm trying to get my head round what you've done.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've just tried your measures in Power BI as I don't have DAX studio installed (it's a work computer, and I can't access the admin permission to install this on a Sunday).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I copied your 3rd measure and had to change the name.&amp;nbsp; I also wasn't allowed to use '[@RT]' - it rejected the use of '@' as a special character, so I just deleted it.&amp;nbsp; In the end, the code I deployed was this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;MEASURE RT3 = 
var CurrentPoint = MAX( 'Test Data'[Point] )
var PrecomputedRTForAllPoints = 
    ADDCOLUMNS(
        'Test Data',
        "RT",
            var CurrentPoint = 'Test Data'[Point]
            return
                SUMX(
                    FILTER(
                        'Test Data',
                        'Test Data'[Point] &amp;lt;= CurrentPoint
                    ),
                    'Test Data'[Point]
                )
    )
var Output = 
    MAXX(
        FILTER(
            PrecomputedRTForAllPoints,
            'Test Data'[Point] = CurrentPoint
        ),
        [RT]
    )
return
    Output&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I added this measure to the table of numbers 1 through to 10,000 , I didn't get the running total, rather just the original series of numbers {1,2,3,4...}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The calculate showed over 9000 ms on the analyzer.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't get your 4th measure to work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I confess I'm a little lost here.&amp;nbsp; It's not clear to me how your measure RT3 produced the times you gave.&amp;nbsp; My DAX isn't good enough I'm afraid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it's wise to revert to my first point: when calculating a running total in DAX I'd like to access a value in the previous column.&amp;nbsp; If I could do this then the code should work quickly AND be easy to read.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 10:51:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2872921#M92789</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-30T10:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2873137#M92800</link>
      <description>&lt;P&gt;Hi Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, I can also show you a screenshot from Power BI itself. &lt;STRONG&gt;The run times are just like the ones that come from DAX Studio.&lt;/STRONG&gt; But I did this in DS because I could run this without the visual's&amp;nbsp; rendering overhead and could benchmark the measures via DS native tools with the automation of the number of runs to get means and standard deviations. It just so happens that it's not necessary at all to be able to access the row before and the brute-force approach is more than good enough to make your code as fast as lightning! That's good news, I guess? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One remark, though. My computer is a beast (Alienware R17) and this obviously had an impact on the numbers. &lt;STRONG&gt;But the relative run times should still stand on any computer, of course.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please send me a link to your file so that I can see what will happen on my machine. By the way, it's a pity you didn't unfold the "Table" entry in Performance Analyzer. Because of this we can't see the breakdown of run times &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 16:22:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2873137#M92800</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-30T16:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2873465#M92813</link>
      <description>&lt;P&gt;DaXtreme, as I mentioned before, I couldn't get the result I wanted (a running total) using your measure #3.&amp;nbsp; I just got the original series of numbers 1,2,3,4 etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to make some changes.&amp;nbsp; I think you named a column [@RT].&amp;nbsp; My version of PowerBI didn't allow the '@' character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd be grateful if you could post&amp;nbsp; a reply with the code that you successfully used in Power BI that worked well so that I can then try it.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 00:50:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2873465#M92813</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-31T00:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2874459#M92861</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OK. You were right that the 2 last measures do not return the cumulative sum. I've found the bug &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Please find a file with all the measures (corrected!) attached. I was too optimistic because the code was calculating a different thing. I need to research more to find out a way to make it faster. But for the time being... the fastest run I could squeeze out of it is about 11-12 secs. That's obiously not good enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://1drv.ms/u/s!ApyQEauTSLtOgfYpjvEOai0V-YTluw?e=ZoLt0G" target="_self"&gt;&lt;STRONG&gt;Here&lt;/STRONG&gt;&lt;/A&gt;'s the link to the file but I've attached the file itself as well.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 10:48:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2874459#M92861</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-31T10:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: a more efficient way to do running totals: why is DAX not efficient at doing this?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2879455#M93135</link>
      <description>&lt;P&gt;DaXtreme, sorry I got a little tied up.&amp;nbsp; I just downloaded your file and tried it on my machine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I set up a table and placed the 'point' value (1 to 10,000) in a column.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I then added the 4 measures you created one at a time onto the table with the performance analyser running&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The results are not encouraging.&amp;nbsp; see screenshot here:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The yellow highlighted figure was a little over 30,000 ms for measure #1&lt;/LI&gt;&lt;LI&gt;The green highlighted figure was a little over 47,000 ms was for measure #2&lt;/LI&gt;&lt;LI&gt;The blue highlighted figure was over 62,000 ms for measure #3&lt;/LI&gt;&lt;LI&gt;Measure #4 performed worse at nearly 78,000 ms&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These figures demonstrate my point.&amp;nbsp; Calculating a cumulative sum without access to the cumulative sum number from the previous row in the table is not efficient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I spoke to the IT manager in my place.&amp;nbsp; He doesn't know Power BI / DAX, but he does know SQL.&amp;nbsp; I explained the issue to him.&amp;nbsp; He couldn't believe that DAX didn't have a way to access the value in the previous row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 08:45:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/a-more-efficient-way-to-do-running-totals-why-is-DAX-not/m-p/2879455#M93135</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-02T08:45:40Z</dc:date>
    </item>
  </channel>
</rss>

