<?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: running total performance issues in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774740#M182860</link>
    <description>&lt;P&gt;This is a problem in Tabular as this calculation is very intensive for the architecture of Tabular.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10.000 Customers is already a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no solution up to now, in the dinamic case performance is awful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this helped, please consider giving kudos and mark as a solution&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="273" data-lia-user-login="me" class="lia-mention lia-mention-user"&gt;me&lt;/a&gt; in replies or I'll lose your thread&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;consider voting &lt;A href="https://community.fabric.microsoft.com/t5/Fabric-Ideas/Power-BI-Filter-Pane-as-an-icon-on-the-right-side-bar-in-on/idi-p/4728588" target="_blank"&gt;this Power BI idea&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Francesco Bergamaschi&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MBA, M.Eng, M.Econ, Professor of BI&lt;/P&gt;</description>
    <pubDate>Thu, 24 Jul 2025 08:04:48 GMT</pubDate>
    <dc:creator>FBergamaschi</dc:creator>
    <dc:date>2025-07-24T08:04:48Z</dc:date>
    <item>
      <title>running total performance issues</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774726#M182859</link>
      <description>&lt;P&gt;I need to create a measure for dynamic ABC analysis and run into heavy performance&amp;nbsp;issues when calculating the running total.&lt;BR /&gt;&lt;BR /&gt;My measure ranks all customers by sales (and keeps filter context of all other dimensions alive) and calculates the running total. It works as intended and I already spent a lot of time doing performance optimization. However, it is&amp;nbsp;still way too slow. It barely even works for 10.000 customers, but it should work for more than 100.000 customers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;running_total =
VAR _my_sales = [Customer Sales]
VAR _allSales =
    FILTER (
        ADDCOLUMNS (
            CALCULATETABLE (
                'Dim Customer',
                CROSSFILTER ( 'Fact Sales'[Customer_SKey], 'Dim Customer'[Customer_SKey], BOTH ),
                REMOVEFILTERS ( 'Dim Customer' )
            ),
            "@Sales", CALCULATE ( [Customer Sales] )
        ),
        [@Sales] &amp;gt; 0
    )
VAR _ranked_sales =
    ADDCOLUMNS (
        _allSales,
        "@runningtotal",
            SUMX (
                WINDOW ( 1, ABS, 0, REL, _allSales, ORDERBY ( [@Sales], DESC ) ),
                [@Sales]
            )
    )
RETURN
    MAXX ( FILTER ( _ranked_sales, [@Sales] = _my_sales ), [@runningtotal] )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Can anybody explain in detail why performance keeps dropping (and maybe even offer a solution)?&lt;BR /&gt;&lt;BR /&gt;Things which do not satisfy the requirements:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;pre-calculations in DWH or M because it needs to be fully dynamic&lt;/LI&gt;&lt;LI&gt;using visual calculations because I might want to select a single customer and view their global ABC class&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Please do not post an AI response. I already spent hours discussing the problem with AI and really hope for human expertise.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 07:46:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774726#M182859</guid>
      <dc:creator>AMeyersen</dc:creator>
      <dc:date>2025-07-24T07:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: running total performance issues</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774740#M182860</link>
      <description>&lt;P&gt;This is a problem in Tabular as this calculation is very intensive for the architecture of Tabular.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10.000 Customers is already a lot&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no solution up to now, in the dinamic case performance is awful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this helped, please consider giving kudos and mark as a solution&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="273" data-lia-user-login="me" class="lia-mention lia-mention-user"&gt;me&lt;/a&gt; in replies or I'll lose your thread&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;consider voting &lt;A href="https://community.fabric.microsoft.com/t5/Fabric-Ideas/Power-BI-Filter-Pane-as-an-icon-on-the-right-side-bar-in-on/idi-p/4728588" target="_blank"&gt;this Power BI idea&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Francesco Bergamaschi&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MBA, M.Eng, M.Econ, Professor of BI&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 08:04:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774740#M182860</guid>
      <dc:creator>FBergamaschi</dc:creator>
      <dc:date>2025-07-24T08:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: running total performance issues</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774950#M182866</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="334992" data-lia-user-login="AMeyersen" class="lia-mention lia-mention-user"&gt;AMeyersen&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;If your report is freezing&amp;nbsp; when you try to calculate running totals over ranked customers, it’s not your fault&amp;nbsp; it’s just Power BI being asked to do way too much.&lt;BR /&gt;When you use things like&lt;SPAN&gt; WINDOW, SUMX&amp;nbsp;and nested filters, Power BI has to stop and think hard for every single customer. Multiply that by 100,000 customers, and yeah… it’s going to struggle.&lt;BR /&gt;&lt;BR /&gt;First Rank Your Customers.&amp;nbsp;Start by giving each customer a rank based on their sales. By using bellow dax.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;Customer Rank = RANKX(ALLSELECTED('Dim Customer'), [Customer Sales],,DESC,DENSE)&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;!-- ScriptorStartFragment --&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;!-- ScriptorEndFragment --&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This tells Power BI who’s #1, #2, #3, etc. It’s quick, respects filters, and sets the stage for everything else.&lt;BR /&gt;&lt;BR /&gt;Then Build the running total.&amp;nbsp;Now use that rank to calculate cumulative sales by using bellow dax.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;Running Total Sales = VAR CurrentRank = [Customer Rank]&lt;BR /&gt;RETURN&lt;BR /&gt;CALCULATE([Customer Sales],FILTER(ALLSELECTED('Dim Customer'),[Customer Rank] &amp;lt;= CurrentRank))&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So if I’m ranked #5, this adds up sales from ranks 1 to 5. Power BI loves this because it doesn’t have to re-do the math for every row.&lt;BR /&gt;&lt;BR /&gt;Optional Bucket customers into A, B, C, Want to group customers by value? Try bellow Dax.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;!-- ScriptorStartFragment --&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class=""&gt;&lt;SPAN&gt;ABC Class =&amp;nbsp;SWITCH(TRUE(),[Customer Rank] &amp;lt;= [Total Customers] * 0.2, "A", [Customer Rank] &amp;lt;= [Total Customers] * 0.5, "B","C")&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;!-- ScriptorEndFragment --&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class=""&gt;
&lt;DIV class="" tabindex="0" role="group" data-fluid-id="E"&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Akhil.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2025 10:31:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4774950#M182866</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-07-24T10:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: running total performance issues</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4776039#M182916</link>
      <description>&lt;P&gt;Hi, thanks for your replies&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Anonymous&lt;/a&gt;&amp;nbsp;your approach runs into the same issues, since [running total sales] uses iterators as well and eats up way too much memory.&lt;BR /&gt;&lt;BR /&gt;I have come up with a different solution where I can avoid running totals alltogether.&lt;BR /&gt;&lt;BR /&gt;The approach is based on z-scores (standard deviation form arithmetic mean). That is something, the storage engine can calculate incredibly fast for huge datasets.&lt;BR /&gt;The second step is, to find the correct threshold for the cumulative sales percentage (e.g. all customers with z-score &amp;gt; 2.5 are responsible for 50% of all sales). This second step of parameter calibration is also very simple in terms of computation power.&lt;BR /&gt;I've come up with a consistent ABC formula which works fast for millions of customers.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ABC-Class =
-- Performs a dynamic ABC classification
-- Replaces traditional running-total iterators with Z-scores
-- → scales to very large datasets without the usual iterator slowdown
-- Target cumulative percentages are approximated within a few points

-- “Magic” constants for the functional approximation g(y) = k / y – c
-- k = slope · c = horizontal shift (tune if your sales distribution changes)
VAR _magic_k = 0.6
VAR _magic_c = 0.9

-- Target cumulative-sales cut-offs for the classes (can be parameterised)
VAR _a_threshold = 0.50     -- top-A customers should cover 50 % of sales
VAR _b_threshold = 0.75     -- A + B together 75 %
VAR _c_threshold = 0.90     -- A + B + C together 90 %

-- Initial Z-score limits derived from the k/c approximation
VAR _z_a_threshold_initial = DIVIDE(_magic_k, _a_threshold) - _magic_c
VAR _z_b_threshold_initial = DIVIDE(_magic_k, _b_threshold) - _magic_c
VAR _z_c_threshold_initial = DIVIDE(_magic_k, _c_threshold) - _magic_c

/* ------------------------------------------------------------------------- */
/* Build a customer-level sales table                                         */
/* Adapt only the two variables below if your model uses other tables/fields */
/* ------------------------------------------------------------------------- */
VAR _customer_sales =
FILTER (
    ADDCOLUMNS (
        CALCULATETABLE (
            'Dim Customer',
            REMOVEFILTERS ( 'Dim Customer' ),
            CROSSFILTER ( 'Fact Sales'[Customer_SKey], 'Dim Customer'[Customer_SKey], BOTH )
        ),
        "@Sales", [Customer Sales]
    ),
    [@Sales] &amp;gt; 0
)

/* Total sales – needed once to adjust the Z-score limits */
VAR _all_sales =
CALCULATE ( [Customer Sales], REMOVEFILTERS ( 'Dim Customer' ) )

/* Mean, standard deviation and Z-score per customer */
VAR _stdev_sales = STDEVX.P ( _customer_sales, [@Sales] )
VAR _avg_sales   = AVERAGEX ( _customer_sales, [@Sales] )
VAR _z_score =
    ADDCOLUMNS (
        _customer_sales,
        "@z_score", DIVIDE ( [@Sales] - _avg_sales, _stdev_sales )
    )

/* ------------------------------------------------------------------------- */
/* One-shot adjustment of the Z-score limits                                 */
/* Using h(x₀,a,y) = (a / y)·(x₀ + c) – c from our functional approximation   */
/* ------------------------------------------------------------------------- */
VAR _a_threshold_actual =
    DIVIDE (
        SUMX ( FILTER ( _z_score, [@z_score] &amp;gt; _z_a_threshold_initial ), [@Sales] ),
        _all_sales
    )
VAR _z_a_threshold_adjusted =
    ( DIVIDE ( _a_threshold_actual, _a_threshold ) * ( _z_a_threshold_initial + _magic_c ) )
    - _magic_c

VAR _b_threshold_actual =
    DIVIDE (
        SUMX ( FILTER ( _z_score, [@z_score] &amp;gt; _z_b_threshold_initial ), [@Sales] ),
        _all_sales
    )
VAR _z_b_threshold_adjusted =
    ( DIVIDE ( _b_threshold_actual, _b_threshold ) * ( _z_b_threshold_initial + _magic_c ) )
    - _magic_c

VAR _c_threshold_actual =
    DIVIDE (
        SUMX ( FILTER ( _z_score, [@z_score] &amp;gt; _z_c_threshold_initial ), [@Sales] ),
        _all_sales
    )
VAR _z_c_threshold_adjusted =
    ( DIVIDE ( _c_threshold_actual, _c_threshold ) * ( _z_c_threshold_initial + _magic_c ) )
    - _magic_c

/* Z-score of the current customer row */
VAR _my_z_score =
    DIVIDE ( [Customer Sales] - _avg_sales, _stdev_sales )

/* ------------------------------------------------------------------------- */
/* Final classification                                                      */
/* ------------------------------------------------------------------------- */
RETURN
    SWITCH (
        TRUE (),
        _my_z_score &amp;gt; _z_a_threshold_adjusted, "A",
        _my_z_score &amp;gt; _z_b_threshold_adjusted, "B",
        _my_z_score &amp;gt; _z_c_threshold_adjusted, "C",
        "D"
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jul 2025 06:56:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/running-total-performance-issues/m-p/4776039#M182916</guid>
      <dc:creator>AMeyersen</dc:creator>
      <dc:date>2025-07-25T06:56:46Z</dc:date>
    </item>
  </channel>
</rss>

