<?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: Circular Reference Error for an Iterative Formula Applied Over Different Rows of the Same Column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057747#M105543</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;In the first version of the problem I've written, your solution is applicable, however, when I include another formula to the consumption column, then again I'm stuck with the circular reference error. Can you check this again?&lt;BR /&gt;&lt;BR /&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;Oytun&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2023 13:58:34 GMT</pubDate>
    <dc:creator>OytunKarabulut</dc:creator>
    <dc:date>2023-02-24T13:58:34Z</dc:date>
    <item>
      <title>Circular Reference Error for an Iterative Formula Applied Over Different Rows of the Same Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057367#M105517</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I'm trying to build an iterative logic with DAX to calculate Opening and Closing Stocks for specific material &amp;amp; rank combinations. How it should go is that;&lt;BR /&gt;- first, I vlookup the Opening Stock value for Rank 1 from a different table.&amp;nbsp;&lt;BR /&gt;- then, I subtract the Consumption from the Opening Stock to come up with the Closing Stock. The Consumptions are dependent on the request, as well as the availability of the opening stock.&lt;BR /&gt;- lastly, I need to assign the Closing Stock of Rank 1 as the Opening Stock of Rank 2, and then the same calculation of Closing Stock should happen for Rank 2.&lt;/P&gt;&lt;P&gt;- and, Rank 2 Closing Stock should be equal to Rank 3 Opening Stock, and so on and so forth...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've created a basic example in Excel where I can refer to individual cells. However, I face a circular reference error when I try to build the same with DAX in Power Pivot or Power BI. I know that DAX calculations are done for each column (and not for each individual cell), however, I still wanted to ask the same to find out if there are any workarounds for this.&lt;BR /&gt;&lt;BR /&gt;When I try to build the same in the Data Modal of the Test File below, I face the circular reference error.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can see this test file below. The DAX formulas are in the Data Model through the Power Pivot tab.&lt;/P&gt;&lt;P&gt;&lt;A href="https://1drv.ms/x/s!Agas-B_GAd6Uc2_BBwiE3HNmlpI?e=3aaJuk" target="_blank" rel="noopener"&gt;Test File.xlsx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you very much for your support everyone,&lt;BR /&gt;Oytun&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 13:55:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057367#M105517</guid>
      <dc:creator>OytunKarabulut</dc:creator>
      <dc:date>2023-02-24T13:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Circular Reference Error for an Iterative Formula Applied Over Different Rows of the Same Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057566#M105527</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="508487" data-lia-user-login="OytunKarabulut" class="lia-mention lia-mention-user"&gt;OytunKarabulut&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Recursion is not possible in DAX, as neither measures nor calculated columns can refer to themselves (indirectly or directly).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, for this particular calculation, you can use a cumulative sum to produce the same results.&lt;/P&gt;
&lt;P&gt;Alternatively, you may want to consider calculating this in Power Query with List.Generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have edited your file and attached an example of how this can be done in DAX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Opening Stock =
VAR CurrentRank = Table1[Rank]
VAR CurrentMaterial = Table1[Material]
VAR OpeningStockLookup =
    CALCULATE (
        SUM ( Table2[Opening Stock] ),
        Table2[Material] = CurrentMaterial
    )
VAR CumulativeConsumption =
    CALCULATE (
        SUM ( Table1[Consumption] ),
        ALLEXCEPT (
            Table1,
            Table1[Material]
        ),
        Table1[Rank] &amp;lt; CurrentRank
    )
RETURN
    OpeningStockLookup - CumulativeConsumption&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Closing Stock =
Table1[Opening Stock] - Table1[Consumption]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Opening Stock&lt;/STRONG&gt; subtracts cumulative Consumption (excluding current Rank) from the original Opening Stock from Table2.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Closing Stock &lt;/STRONG&gt;subtracts Consumption for current Rank from &lt;STRONG&gt;Opening Stock&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;There are some possible variations on the DAX code above, but the logic should be similar regardless.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 10:35:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057566#M105527</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-02-02T10:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Circular Reference Error for an Iterative Formula Applied Over Different Rows of the Same Column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057747#M105543</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;In the first version of the problem I've written, your solution is applicable, however, when I include another formula to the consumption column, then again I'm stuck with the circular reference error. Can you check this again?&lt;BR /&gt;&lt;BR /&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;Oytun&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2023 13:58:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Circular-Reference-Error-for-an-Iterative-Formula-Applied-Over/m-p/3057747#M105543</guid>
      <dc:creator>OytunKarabulut</dc:creator>
      <dc:date>2023-02-24T13:58:34Z</dc:date>
    </item>
  </channel>
</rss>

