<?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 Repeated Calculated Column Optimization in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4631492#M177331</link>
    <description>&lt;P&gt;Dear community, I have a table need to add several calculation columns.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Day0 = '1'[Qty]-'1'[Qty]/('1'[End_GroupQty_Previous]+'1'[VS_Qty])*'1'[Capacity]

Day1 = 
VAR CurrentDate = '1'[MAV]
VAR CurrentVS = '1'[VS]
VAR CurrentLine = '1'[Line]
VAR Previous_Qty2 =
    CALCULATE(
        MAX('1'[Day0]),
        FILTER(
            '1',
            '1'[vs] = CurrentVS &amp;amp;&amp;amp;
            '1'[line] = CurrentLine &amp;amp;&amp;amp;
            '1'[mav] &amp;lt; CurrentDate
        ),
        TOPN(1, 
            FILTER('1', '1'[vs] = CurrentVS &amp;amp;&amp;amp; '1'[line] = CurrentLine &amp;amp;&amp;amp; '1'[mav] &amp;lt; CurrentDate), 
            '1'[mav], 
            DESC
        )
    )
RETURN
    ('1'[Qty] + Previous_Qty2) - 
    ('1'[Qty] + Previous_Qty2) / ('1'[End_GroupQty_Previous] + '1'[VS_Qty]) * '1'[Capacity]


Day2 = 
VAR CurrentDate = '1'[MAV]
VAR CurrentVS = '1'[VS]
VAR CurrentLine = '1'[Line]
VAR Previous_Qty2 =
    CALCULATE(
        MAX('1'[Day1]),
        FILTER(
            '1',
            '1'[vs] = CurrentVS &amp;amp;&amp;amp;
            '1'[line] = CurrentLine &amp;amp;&amp;amp;
            '1'[mav] &amp;lt; CurrentDate
        ),
        TOPN(1, 
            FILTER('1', '1'[vs] = CurrentVS &amp;amp;&amp;amp; '1'[line] = CurrentLine &amp;amp;&amp;amp; '1'[mav] &amp;lt; CurrentDate), 
            '1'[mav], 
            DESC
        )
    )
RETURN
    ('1'[Qty] + Previous_Qty2) - 
    ('1'[Qty] + Previous_Qty2) / ('1'[End_GroupQty_Previous] + '1'[VS_Qty]) * '1'[Capacity]
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same logic for day2 applied on days3 and next by only change last row '1'[Qty] to '2'[Qty], '3'[Qty]…&lt;/P&gt;&lt;P&gt;In other words, in order to get Day9, I have to create columns next from Day3 to Day9.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Do we have other ways to use recurrence and create day9 directly? I Attached my sample file for your reference.&lt;/P&gt;&lt;P&gt;&lt;!-- StartFragment  --&gt;&lt;A href="https://1drv.ms/u/c/f2ee584877db0819/ERBy_pKGa-5IuBwzxmaXfgYBoJvgSai9GIjPyUBBz-_oLA?e=A7KKen" target="_blank"&gt;sample.pbix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 31 Mar 2025 12:18:47 GMT</pubDate>
    <dc:creator>NBU_FFF</dc:creator>
    <dc:date>2025-03-31T12:18:47Z</dc:date>
    <item>
      <title>Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4631492#M177331</link>
      <description>&lt;P&gt;Dear community, I have a table need to add several calculation columns.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Day0 = '1'[Qty]-'1'[Qty]/('1'[End_GroupQty_Previous]+'1'[VS_Qty])*'1'[Capacity]

Day1 = 
VAR CurrentDate = '1'[MAV]
VAR CurrentVS = '1'[VS]
VAR CurrentLine = '1'[Line]
VAR Previous_Qty2 =
    CALCULATE(
        MAX('1'[Day0]),
        FILTER(
            '1',
            '1'[vs] = CurrentVS &amp;amp;&amp;amp;
            '1'[line] = CurrentLine &amp;amp;&amp;amp;
            '1'[mav] &amp;lt; CurrentDate
        ),
        TOPN(1, 
            FILTER('1', '1'[vs] = CurrentVS &amp;amp;&amp;amp; '1'[line] = CurrentLine &amp;amp;&amp;amp; '1'[mav] &amp;lt; CurrentDate), 
            '1'[mav], 
            DESC
        )
    )
RETURN
    ('1'[Qty] + Previous_Qty2) - 
    ('1'[Qty] + Previous_Qty2) / ('1'[End_GroupQty_Previous] + '1'[VS_Qty]) * '1'[Capacity]


Day2 = 
VAR CurrentDate = '1'[MAV]
VAR CurrentVS = '1'[VS]
VAR CurrentLine = '1'[Line]
VAR Previous_Qty2 =
    CALCULATE(
        MAX('1'[Day1]),
        FILTER(
            '1',
            '1'[vs] = CurrentVS &amp;amp;&amp;amp;
            '1'[line] = CurrentLine &amp;amp;&amp;amp;
            '1'[mav] &amp;lt; CurrentDate
        ),
        TOPN(1, 
            FILTER('1', '1'[vs] = CurrentVS &amp;amp;&amp;amp; '1'[line] = CurrentLine &amp;amp;&amp;amp; '1'[mav] &amp;lt; CurrentDate), 
            '1'[mav], 
            DESC
        )
    )
RETURN
    ('1'[Qty] + Previous_Qty2) - 
    ('1'[Qty] + Previous_Qty2) / ('1'[End_GroupQty_Previous] + '1'[VS_Qty]) * '1'[Capacity]
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The same logic for day2 applied on days3 and next by only change last row '1'[Qty] to '2'[Qty], '3'[Qty]…&lt;/P&gt;&lt;P&gt;In other words, in order to get Day9, I have to create columns next from Day3 to Day9.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Do we have other ways to use recurrence and create day9 directly? I Attached my sample file for your reference.&lt;/P&gt;&lt;P&gt;&lt;!-- StartFragment  --&gt;&lt;A href="https://1drv.ms/u/c/f2ee584877db0819/ERBy_pKGa-5IuBwzxmaXfgYBoJvgSai9GIjPyUBBz-_oLA?e=A7KKen" target="_blank"&gt;sample.pbix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 12:18:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4631492#M177331</guid>
      <dc:creator>NBU_FFF</dc:creator>
      <dc:date>2025-03-31T12:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4631705#M177336</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="677694" data-lia-user-login="NBU_FFF" class="lia-mention lia-mention-user"&gt;NBU_FFF&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The best approach to optimize your repeated Day0–Day9 calculated columns is to offload the recursive logic into Power Query using index-based row referencing. DAX is not well-suited for recursion over calculated columns because it lacks true looping behavior and cannot reference previously calculated column values in subsequent rows. Power Query, on the other hand, allows row-by-row processing using index columns and custom steps. You can start by sorting your table by [Line], [VS], and [MAV], then add an index column starting from 0. This index will serve as the “day” indicator, and you can reference the previous row's result for the recursive logic. After adding the index, you create a custom column such as [DayQty] using a recursive function. Here’s a simplified version of how the logic might look:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    SortedRows = Table.Sort(Source,{{"Line", Order.Ascending}, {"VS", Order.Ascending}, {"MAV", Order.Ascending}}),
    AddIndex = Table.AddIndexColumn(SortedRows, "Day", 0, 1, Int64.Type),
    AddDayQty = Table.AddColumn(AddIndex, "DayQty", each null, type number),
    RecursiveCalculation = List.Accumulate(
        {0..Table.RowCount(AddDayQty)-1},
        AddDayQty,
        (state, current) =&amp;gt;
            let
                row = state{current},
                prev = if current = 0 then null else state{current - 1},
                qty = row[Qty],
                cap = row[Capacity],
                endGroupQty = row[End_GroupQty_Previous],
                vsQty = row[VS_Qty],
                prevQty = if current = 0 then null else prev[DayQty],
                calc = if current = 0 then
                    qty - qty / (endGroupQty + vsQty) * cap
                else
                    (qty + prevQty) - (qty + prevQty) / (endGroupQty + vsQty) * cap,
                newState = Table.ReplaceRows(state, current, {Record.TransformFields(row, {"DayQty", each calc})})
            in
                newState
    )
in
    RecursiveCalculation
&lt;/LI-CODE&gt;
&lt;P&gt;This logic processes the table row-by-row while calculating the DayQty recursively. The first row (Day0) uses your original formula, and all subsequent rows use the previous row’s DayQty to compute the current one. This way, you no longer need to manually create Day1 to Day9 columns in DAX. You end up with a single [DayQty] column that contains the recursive result for each day index, and the logic can be extended to as many days as needed without repetition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 14:50:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4631705#M177336</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2025-03-31T14:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633393#M177377</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="608865" data-lia-user-login="DataNinja777" class="lia-mention lia-mention-user"&gt;DataNinja777&lt;/a&gt;&amp;nbsp;thanks a lot for your reply and explain. Unfortunately my data was combined from different sources and could not be processed in Power Query only. What's why I asked for the help with DAX.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 13:26:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633393#M177377</guid>
      <dc:creator>NBU_FFF</dc:creator>
      <dc:date>2025-04-01T13:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633503#M177388</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="677694" data-lia-user-login="NBU_FFF" class="lia-mention lia-mention-user"&gt;NBU_FFF&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies, my bad, DAX does not support true recursion, especially in calculated columns or tables where the value of a row depends on the value of a previous row in the same column.&amp;nbsp;If you're trying to implement logic where each "DayN" calculation depends on the previous day’s result, DAX is not the right tool for this kind of recursion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 14:51:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633503#M177388</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2025-04-01T14:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633556#M177390</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="608865" data-lia-user-login="DataNinja777" class="lia-mention lia-mention-user"&gt;DataNinja777&lt;/a&gt;&amp;nbsp; Thanks for your help again. I tried but showed error below:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seemed DAX not support&amp;nbsp;Recursive, not sure how you achieve that without error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached my PBI file here, could you pls have a look?&lt;/P&gt;&lt;P&gt;&lt;!-- StartFragment  --&gt;&lt;A href="https://1drv.ms/u/c/f2ee584877db0819/EQ2nfc3Xcp5Ok4uOI7nUh5wBul25qftjZswBfaLdrHiFIw?e=plzFYA" target="_blank"&gt;sample_Dax.pbix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 14:42:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4633556#M177390</guid>
      <dc:creator>NBU_FFF</dc:creator>
      <dc:date>2025-04-01T14:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4636614#M177513</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="677694" data-lia-user-login="NBU_FFF" class="lia-mention lia-mention-user"&gt;NBU_FFF&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DAX doesn't support true recursion in calculated columns or tables because it lacks row-by-row iteration based on previous results. Since Power Query isn't an option either, the best approach would be to use a &lt;STRONG&gt;measure&lt;/STRONG&gt; instead of calculated columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Limitation&lt;/STRONG&gt;: This won’t work for deep recursion across multiple rows because DAX measures rely on context, not row-by-row memory like Power Query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider &lt;STRONG&gt;Accepting as solution&lt;/STRONG&gt; to help the other members find it more quickly, don't forget to give a "&lt;STRONG&gt;Kudos&lt;/STRONG&gt;" – I’d truly appreciate it!&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Vinay Pabbu&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 11:18:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4636614#M177513</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-04-03T11:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4641024#M177712</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="677694" data-lia-user-login="NBU_FFF" class="lia-mention lia-mention-user"&gt;NBU_FFF&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Regards,&lt;/P&gt;
&lt;P&gt;Chaithanya.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 12:04:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4641024#M177712</guid>
      <dc:creator>v-kathullac</dc:creator>
      <dc:date>2025-04-07T12:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4648616#M177946</link>
      <description>&lt;P&gt;Hi&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/677694" target="_blank"&gt;@NBU_FFF&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Regards,&lt;/P&gt;
&lt;P&gt;Chaithanya.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 11:43:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4648616#M177946</guid>
      <dc:creator>v-kathullac</dc:creator>
      <dc:date>2025-04-11T11:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Calculated Column Optimization</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4657921#M178351</link>
      <description>&lt;P&gt;Hi&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/677694" target="_blank"&gt;@NBU_FFF&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Regards,&lt;/P&gt;
&lt;P&gt;Chaithanya.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Apr 2025 16:04:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Repeated-Calculated-Column-Optimization/m-p/4657921#M178351</guid>
      <dc:creator>v-kathullac</dc:creator>
      <dc:date>2025-04-17T16:04:59Z</dc:date>
    </item>
  </channel>
</rss>

