<?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: Cummulative Prev Change in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838770#M6302</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;The solution at this point is two columns.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Let me know if you have any questions.&lt;BR /&gt;&lt;BR /&gt;If this solves your issues, please mark it as the &lt;STRONG&gt;solution, &lt;/STRONG&gt;so that others can find it easily. &lt;STRONG&gt;Kudos &lt;/STRONG&gt;are nice too.&lt;BR /&gt;Nathaniel&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cumulative = 

var _curIndex =PA_KEY[Index]
var _minIndex = CALCULATE(MIN(PA_KEY[Index]),ALLEXCEPT(PA_KEY,PA_KEY[PA#]),PA_KEY[Index]&amp;lt;_curIndex)

return

IF(_curIndex = _minIndex || _curIndex = _minIndex+1,BLANK(), CALCULATE(sum(PA_KEY[RequestedValue]),ALLEXCEPT(PA_KEY,PA_KEY[PA#]),PA_KEY[Index]=_curIndex -1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cumulative and previous = 
VAR _curIndex = PA_KEY[Index]   //Get current Index from this row
VAR _minIndex = CALCULATE ( MIN ( PA_KEY[Index] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] &amp;lt; _curIndex )    //Get minimum index for this PA#                                
                              
VAR _prev3 = CALCULATE ( SUM ( PA_KEY[Cumulative] ),  ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] = _curIndex - 1 )   // Get the previous row amount from the Cumulative column                                

RETURN
    IF (                                        //Return a blank if the current index is equal to the first two rows of this PA# else do the calc and add the previous row from the Cumulative column
        _curIndex = _minIndex
            || _curIndex = _minIndex + 1,
        BLANK (),
        CALCULATE (
            SUM ( PA_KEY[RequestedValue] ),
            ALLEXCEPT (
                PA_KEY,
                PA_KEY[PA#]
            ),
            PA_KEY[Index] = _curIndex - 1
        ) + _prev3
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2019 14:18:00 GMT</pubDate>
    <dc:creator>Nathaniel_C</dc:creator>
    <dc:date>2019-11-06T14:18:00Z</dc:date>
    <item>
      <title>Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/837799#M6270</link>
      <description>&lt;P&gt;Good afternoon&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with a DAX formula, and will appreciate some help&lt;/P&gt;&lt;P&gt;Want to create a formula for "Cummulative Prev Change" as per screenshot and following conditions&lt;/P&gt;&lt;P&gt;1) First two rows have to be zero&lt;/P&gt;&lt;P&gt;2) from 3rd row, the formula should get PreviousVersions's "Requested Value" +&amp;nbsp;PreviousVersions's "Cummulative Prev Change" if&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried following formula, to no effect &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CummulativePrevChange2 = IF(PA_KEY[Version]&amp;gt;1,LOOKUPVALUE(PA_KEY[RequestedValue],PA_KEY[Version],PA_KEY[Version]-1,PA_KEY[PA#],PA_KEY[PA#]),0)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Attached are the sample file and screenshot of how the column should calculate values...&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;A title="PowerBI File" href="https://drive.google.com/file/d/1b0w01JPFI7kB1KCng-4FYTwCgxv55Qzz/view?usp=sharing" target="_self"&gt;PowerBI File&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;A title="How it should look like" href="https://drive.google.com/file/d/10ZBLe3ivCEeV67JQvsaZ1QTpiV69c1Zn/view?usp=sharing" target="_self"&gt;How it should look like&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you in advance for any advise &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 05 Nov 2019 19:07:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/837799#M6270</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-05T19:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/837956#M6279</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 22:48:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/837956#M6279</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2019-11-05T22:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838729#M6300</link>
      <description>&lt;P&gt;thank you Nathan,&lt;/P&gt;&lt;P&gt;Kindly can you share the DAX for your column?&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;P&gt;-Usman&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 13:37:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838729#M6300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-06T13:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838770#M6302</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;The solution at this point is two columns.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Let me know if you have any questions.&lt;BR /&gt;&lt;BR /&gt;If this solves your issues, please mark it as the &lt;STRONG&gt;solution, &lt;/STRONG&gt;so that others can find it easily. &lt;STRONG&gt;Kudos &lt;/STRONG&gt;are nice too.&lt;BR /&gt;Nathaniel&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cumulative = 

var _curIndex =PA_KEY[Index]
var _minIndex = CALCULATE(MIN(PA_KEY[Index]),ALLEXCEPT(PA_KEY,PA_KEY[PA#]),PA_KEY[Index]&amp;lt;_curIndex)

return

IF(_curIndex = _minIndex || _curIndex = _minIndex+1,BLANK(), CALCULATE(sum(PA_KEY[RequestedValue]),ALLEXCEPT(PA_KEY,PA_KEY[PA#]),PA_KEY[Index]=_curIndex -1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cumulative and previous = 
VAR _curIndex = PA_KEY[Index]   //Get current Index from this row
VAR _minIndex = CALCULATE ( MIN ( PA_KEY[Index] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] &amp;lt; _curIndex )    //Get minimum index for this PA#                                
                              
VAR _prev3 = CALCULATE ( SUM ( PA_KEY[Cumulative] ),  ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] = _curIndex - 1 )   // Get the previous row amount from the Cumulative column                                

RETURN
    IF (                                        //Return a blank if the current index is equal to the first two rows of this PA# else do the calc and add the previous row from the Cumulative column
        _curIndex = _minIndex
            || _curIndex = _minIndex + 1,
        BLANK (),
        CALCULATE (
            SUM ( PA_KEY[RequestedValue] ),
            ALLEXCEPT (
                PA_KEY,
                PA_KEY[PA#]
            ),
            PA_KEY[Index] = _curIndex - 1
        ) + _prev3
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 14:18:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838770#M6302</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2019-11-06T14:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838775#M6303</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="106637" data-lia-user-login="jdbuchanan71" class="lia-mention lia-mention-user"&gt;jdbuchanan71&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;You are in luck! This is from&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="106637" data-lia-user-login="jdbuchanan71" class="lia-mention lia-mention-user"&gt;jdbuchanan71&lt;/a&gt;&amp;nbsp;, one column and much simpler code.&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;Hi Nathaniel,

The problem I see is how to determine the order of the lines.  I know you added an index but will the rows always come out of the source in the right order?  I would verify that with the original poster.

If the index can be added safely then this code should work.

Column = 
VAR _MinIndex = CALCULATE ( MIN ( PA_KEY[Index] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ) )
VAR _RowIndex = [Index]
RETURN CALCULATE ( SUM ( PA_KEY[RequestedValue] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] &amp;gt; _MinIndex &amp;amp;&amp;amp; PA_KEY[Index] &amp;lt; _RowIndex )


=========================

We don't need to do any checking for the first 2 rows because the filters  PA_KEY[Index] &amp;gt; _MinIndex &amp;amp;&amp;amp; PA_KEY[Index] &amp;lt; _RowIndex take care of it.

On index line 5 for example.

_MinIndex = 4

_RowIndex = 5




We ask for the sum of PA_KEY[RequestedValue] where the Index is &amp;gt; 4 AND &amp;lt; 5.  No such lines so we get nothing.
On Index line 7 we as for the sum of [RequestedValue] where the Index &amp;gt; 4 AND &amp;lt; 7.  We get the sum of Index 5 and 6&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nathaniel&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 14:28:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838775#M6303</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2019-11-06T14:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838809#M6306</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just this portion is the measure and it relies on the index column&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="159166" data-lia-user-login="Nathaniel_C" class="lia-mention lia-mention-user"&gt;Nathaniel_C&lt;/a&gt;&amp;nbsp; added to your sample table.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column = 
VAR _MinIndex = CALCULATE ( MIN ( PA_KEY[Index] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ) )
VAR _RowIndex = [Index]
RETURN CALCULATE ( SUM ( PA_KEY[RequestedValue] ), ALLEXCEPT ( PA_KEY, PA_KEY[PA#] ), PA_KEY[Index] &amp;gt; _MinIndex &amp;amp;&amp;amp; PA_KEY[Index] &amp;lt; _RowIndex )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Are you able to add an index column to your source data that will properly order the lines?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 14:58:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/838809#M6306</guid>
      <dc:creator>jdbuchanan71</dc:creator>
      <dc:date>2019-11-06T14:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839037#M6313</link>
      <description>&lt;P&gt;thank you JDBuchanon, and Nathan for your replies&lt;/P&gt;&lt;P&gt;Adding an index (order by) will make query quite slow.&lt;/P&gt;&lt;P&gt;Is there any other suggestions without adding index column please ?&lt;/P&gt;&lt;P&gt;thank you again&lt;/P&gt;&lt;P&gt;-Usman&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 19:11:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839037#M6313</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-06T19:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839038#M6314</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data always come into the model in the correct order you can just add an index row in the query editor the way&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="159166" data-lia-user-login="Nathaniel_C" class="lia-mention lia-mention-user"&gt;Nathaniel_C&lt;/a&gt;&amp;nbsp;did.&lt;/P&gt;
&lt;P&gt;Without an index column, what it the logic to determine "previous row"?&amp;nbsp; Keep in mind that PowerBI does not understand "this row is the row before the row I am on" the way excel does.&amp;nbsp; That is why we need an index column or some other logic to tell PowerBI how to search the entire table and find the previous rows.&amp;nbsp; Also, what is your data source for the information?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 19:17:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839038#M6314</guid>
      <dc:creator>jdbuchanan71</dc:creator>
      <dc:date>2019-11-06T19:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839062#M6315</link>
      <description>&lt;P&gt;thanks for your reply&lt;/P&gt;&lt;P&gt;"PA_Key" and "Invoice Line" is the unique key/index; e.g. "1043-1-1" which shows "Purchase Order-Version#-Invoice Line#" respectively&lt;/P&gt;&lt;P&gt;Can we somehow use the original table to do it, or would we have to add a new index and use order by clause, to always order them by Purchase Order, Invoice Line#, Version # ?&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 19:40:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839062#M6315</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-06T19:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839066#M6316</link>
      <description>&lt;P&gt;The problem with using the original table is you don't know what order the lines are going to come in unless you give it an order by.&amp;nbsp; You could add the index on the SQL side as well, something like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;SELECT
	PA_Key,
	Version,
	[Invoice LINE],
	CONTRACTLINEVALUE,
	REQUESTEDVALUE,
	PA#,
	ROW_NUMBER() OVER( ORDER BY ( SELECT 0 ) ) AS RowIndex
FROM Table
ORDER BY
	PA_Key,
	Version,
	[Invoice LINE]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 19:53:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/839066#M6316</guid>
      <dc:creator>jdbuchanan71</dc:creator>
      <dc:date>2019-11-06T19:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cummulative Prev Change</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/840285#M6349</link>
      <description>&lt;P&gt;Thank you JDBuchanan and Nathan, for all you help.&lt;/P&gt;&lt;P&gt;Much appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 20:58:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Cummulative-Prev-Change/m-p/840285#M6349</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-07T20:58:59Z</dc:date>
    </item>
  </channel>
</rss>

