<?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: Recursion in DAX in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2644055#M77752</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;To my knowledge, this doesn't seem very possible. You could try doing the calculations in excel first and then import it into power bi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2022 07:42:33 GMT</pubDate>
    <dc:creator>v-chenwuz-msft</dc:creator>
    <dc:date>2022-07-18T07:42:33Z</dc:date>
    <item>
      <title>Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633314#M77122</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a &lt;STRONG&gt;DAX&lt;/STRONG&gt; &lt;STRONG&gt;measure&lt;/STRONG&gt;&amp;nbsp;(not calculated column) that calculates monthly KPI, and needs to refer to it's previous months' result to get current month number.&lt;/P&gt;&lt;P&gt;It's like something below:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already have a DAX measure to calculate X = x1, x2, x3, ... (for each month)&lt;/P&gt;&lt;PRE&gt;Current month X = CALCULATE(SUMX(MyTable, [X]))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cumulative X = 
var ThisMonth = SELECTEDVALUE(MyCalendar[Month])
return CALCULATE(SUMX(MyTable, [Current month X]), All(MyCalendar), MyCalendar[Month] &amp;lt;= ThisMonth))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, for Y, it's calculated based on&lt;/P&gt;&lt;P&gt;[Current month Y] = [Current month's cumulative X] - [Previous month's cumulative Y]&lt;/P&gt;&lt;P&gt;where [Previous month's cumulative Y] is the sum of [Current month Y] for every month until previous month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is causing a circular dependency in my DAX measure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Current month Y = 
CALCULATE(SUMX(MyTable, [Cumulative X] - [Cumulative Y (last month)]))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Cumulative Y (last month) = 
var ThisMonth = SELECTEDVALUE(MyCalendar[Month])
var LastMonth = EDATE(ThisMonth, -1)
return CALCULATE(SUMX(MyTable, [Current month Y]), All(MyCalendar), MyCalendar[Month] &amp;lt;= LastMonth))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I saw some post saying that DAX cannot do recursively self-reference, and I also cannot write table to store the previous month's calculation result as I need the calculation to be &lt;STRONG&gt;on-the-fly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips or workaround idea would be very much appreciated! Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 10:13:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633314#M77122</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-12T10:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633429#M77130</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , based on screen shot, seem like you need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(all('Date'),'Date'[date] &amp;lt;=max('Date'[date])))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected('Date'),'Date'[date] &amp;lt;=max('Date'[date])))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running Total/ Cumulative: &lt;A href="https://www.youtube.com/watch?v=h2wsO332LUo&amp;amp;list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&amp;amp;index=41" target="_blank"&gt;https://www.youtube.com/watch?v=h2wsO332LUo&amp;amp;list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&amp;amp;index=41&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 10:56:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633429#M77130</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-07-12T10:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633482#M77133</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the quick response! I did tried something like that, however, as the current month's [Y] is based on it's previous month's cumulative [Y] result,&amp;nbsp;it will cause a &lt;STRONG&gt;circular dependency&lt;/STRONG&gt; &lt;STRONG&gt;error&lt;/STRONG&gt; if I tried to calculate &lt;STRONG&gt;cumulative&lt;/STRONG&gt; [Y]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Current month Y = 
CALCULATE(SUMX(MyTable, [Cumulative X] - [Cumulative Y (last month)]))&lt;/LI-CODE&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;&lt;PRE&gt;Cumulative Y (last month) = 
var ThisMonth = SELECTEDVALUE(MyCalendar[Month])
var LastMonth = EDATE(ThisMonth, -1)
return CALCULATE(SUMX(MyTable, [Current month Y]), All(MyCalendar), MyCalendar[Month] &amp;lt;= LastMonth))&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2022 11:16:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2633482#M77133</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-12T11:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2640832#M77523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indeed, it is not possible to compute formulas with circular dependencies in power bi.&lt;/P&gt;
&lt;P&gt;However, we can avoid this problem from a mathematical point of view. It seems to follow from the screenshot that x=y, and you can try to prove it.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If i misunderstood you, please share some example data and expcet result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 09:08:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2640832#M77523</guid>
      <dc:creator>v-chenwuz-msft</dc:creator>
      <dc:date>2022-07-15T09:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2641084#M77545</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="320777" data-lia-user-login="v-chenwuz-msft" class="lia-mention lia-mention-user"&gt;v-chenwuz-msft&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;you were right about the example here (sorry I was trying to simplify the problem to see if I can find a general solution for a recursive function)&lt;/P&gt;&lt;P&gt;The actual problem I was trying to solve is a bit more complicated than the example, where&lt;/P&gt;&lt;P&gt;y1 = IF(x1 &amp;gt;0, x1, 0)&lt;/P&gt;&lt;P&gt;y2 = IF( (x1+x2)-(y1) &amp;gt;0, (x1+x2)- (y1), 0)&lt;/P&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;P&gt;so x is only equal to y when the difference between cumulative x and last cumulative y is all positive&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions for this? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 10:11:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2641084#M77545</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-15T10:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2641410#M77562</link>
      <description>&lt;P&gt;Perhaps post some more realistic data (copiable, not a picture), together with expected results.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 12:47:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2641410#M77562</guid>
      <dc:creator>Jos_Woolley</dc:creator>
      <dc:date>2022-07-15T12:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2642886#M77673</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have a problem that calls for recursion in DAX... well, then you've basically got 2 choices: 1) either you'll find a non-recursive formula or 2) you'll move the calculation to Power Query/source system. The best solution is to be able to find a non-recursive formula, of course, and sometimes it's possible with a bit of mathematical wizardry but sometimes, sadly, it's simply impossible or just too difficult to do. Then, of course, you don't have a choice &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; By experience I can tell you that if you have a formula with IF's in it and it's recursive, then there are very slim chances to obtain an iterative one...&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2022 08:56:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2642886#M77673</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-07-17T08:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: Recursion in DAX</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2644055#M77752</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To my knowledge, this doesn't seem very possible. You could try doing the calculations in excel first and then import it into power bi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 07:42:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Recursion-in-DAX/m-p/2644055#M77752</guid>
      <dc:creator>v-chenwuz-msft</dc:creator>
      <dc:date>2022-07-18T07:42:33Z</dc:date>
    </item>
  </channel>
</rss>

