<?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: Problem with the column that calculates the previous value of a column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412625#M63612</link>
    <description>&lt;P&gt;The problem with your index column is that it will give the same result to different entries with the same date, and so you have the same problem as before.&lt;/P&gt;&lt;P&gt;I would use Power Query to add the column. Sort by the date column then add an index column, doesn't matter whether it starts from 0 or 1.&lt;/P&gt;&lt;P&gt;That will guarantee that there will be a unique index and you can use that in TOPN&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 14:20:21 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2022-03-23T14:20:21Z</dc:date>
    <item>
      <title>Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2411989#M63562</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have table "prod_snapshot", that is snapshot data of customer records. The table has a calculated column "default tagi", that tags default with an IF-statement, returning either 1 or 0 based on whether the customer is defaulted or not. I need a column that returns the previous value of a default tagi column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have used syntax:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;previous default = &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;FIRSTNONBLANK&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[default tagi]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt; ),&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;filter&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;earlier&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;SPAN&gt;) &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[Year Month order]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;earlier&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[Year Month order]&lt;/SPAN&gt;&lt;SPAN&gt;))).&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The Year Month Order is a column that gives order number for each month in an ascending order.&lt;BR /&gt;The problem is that for some customer records (=loan_id) it works and for some it gives the current value of default tagi.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When Year Month Order = 98 previous default returns 1, that is not the previous value of default tagi.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;img /&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;For this loan_id, it returns the correct value:&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;img /&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;SPAN&gt;Could anyone help me with this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Mar 2022 10:32:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2411989#M63562</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-23T10:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412268#M63581</link>
      <description>&lt;LI-CODE lang="csharp"&gt;define table Loans =
SELECTCOLUMNS(
    {
        (1, 1, 0),
        (1, 2, 0),
        (1, 3, 1),
        ----------
        (2, 1, 0),
        (2, 2, 1),
        (2, 3, 1)
    },
    "loan_id", [Value1],
    "ym_order", [Value2],
    "def_tagi", [Value3]
)
EVALUATE
    ADDCOLUMNS(
        Loans,
        "prev_def",
            var curr_loan_id = Loans[loan_id]
            var curr_ym_order = Loans[ym_order]
            var prev_def_tagi =
                MAXX(
                    filter(
                        Loans,
                        Loans[loan_id] = curr_loan_id
                        &amp;amp;&amp;amp;
                        Loans[ym_order] = curr_ym_order - 1
                    ),
                    Loans[def_tagi]
                )
            return
                COALESCE( prev_def_tagi, 0 )
    )&lt;/LI-CODE&gt;&lt;P&gt;Run this in DAX Studio. The definition of "prev_def" is what you need.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 12:20:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412268#M63581</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-03-23T12:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412276#M63583</link>
      <description>&lt;P&gt;You can use TOPN&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;previous default =
var currentLoan = 'Table'[loan_id]
var currentYearMonth = 'Table'[Year Month order]
return SELECTCOLUMNS( TOPN(1, CALCULATETABLE( REMOVEFILTERS('Table'), 
   'Table'[loan_id] = currentLoan &amp;amp;&amp;amp; 'Table'[Year Month order] &amp;lt; currentYearMonth ),
   'Table'[Year Month order], DESC),
"@value", 'Table'[default tagi]
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 12:24:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412276#M63583</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-03-23T12:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412472#M63602</link>
      <description>&lt;P&gt;Thanks for your reply! Unfortunately, it doesn't work. I replaced REMOVEFILTERS() with ALL(), as apparently REMOVEFILTERS cannot be used with calculatetable expression, but still throws this error message:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 13:35:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412472#M63602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-23T13:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412480#M63603</link>
      <description>&lt;P&gt;Do you have multiple entries in a month for a loan ? If so you may need to add a unique index column using Power Query and you can then add that index column as another sort on the TOPN, that should only return 1 value per loan then&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 13:40:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412480#M63603</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-03-23T13:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412577#M63609</link>
      <description>&lt;P&gt;Yes I have, but I want that the previous default column considerers only those values from default tagi -column that are from different month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made Index column, that gives different index for every report date:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Index = &lt;/SPAN&gt;&lt;SPAN&gt;RANKX&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;EARLIER&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;SPAN&gt;) = &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;[report_date]&lt;/SPAN&gt;&lt;SPAN&gt;,, &lt;/SPAN&gt;&lt;SPAN&gt;ASC&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Then I tried to plug this into TOPN- function:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;previous default = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;currentLoan&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;currentYearMonth&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[Year Month order]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;SELECTCOLUMNS&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;TOPN&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATETABLE&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;'prod snapshot'[loan_id]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;currentLoan&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[Year Month order]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt; &lt;/SPAN&gt;&lt;SPAN&gt;currentYearMonth&lt;/SPAN&gt;&lt;SPAN&gt; ),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;'prod snapshot'[Index]&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;DESC&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"@value"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'prod snapshot'[default tagi]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;It still gives the same error. I am pretty new to power bi, so I am not quite sure about how that function operates. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Could you please show me how it should be included and if the Index column is correctly defined?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 23 Mar 2022 14:08:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412577#M63609</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-23T14:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412625#M63612</link>
      <description>&lt;P&gt;The problem with your index column is that it will give the same result to different entries with the same date, and so you have the same problem as before.&lt;/P&gt;&lt;P&gt;I would use Power Query to add the column. Sort by the date column then add an index column, doesn't matter whether it starts from 0 or 1.&lt;/P&gt;&lt;P&gt;That will guarantee that there will be a unique index and you can use that in TOPN&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 14:20:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412625#M63612</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-03-23T14:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412710#M63616</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;could you please try the below DAX code&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 14:42:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412710#M63616</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-23T14:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412712#M63617</link>
      <description>&lt;P&gt;Thanks, the index column was easy to do in Power Query as you told.&lt;/P&gt;&lt;P&gt;The TOPN-function works now, but now previous default column seems to return"1" for every report date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Was the TOPN -function correct as I posted it or should the Index column be included in a different way?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 14:46:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412712#M63617</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-23T14:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412779#M63624</link>
      <description>&lt;P&gt;Replace the CALCULATETABLE with FILTER, that works in the sample I've mocked up.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 15:06:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2412779#M63624</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-03-23T15:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with the column that calculates the previous value of a column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2421112#M64142</link>
      <description>&lt;P&gt;That works, thanks a lot for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 09:47:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-with-the-column-that-calculates-the-previous-value-of-a/m-p/2421112#M64142</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-28T09:47:09Z</dc:date>
    </item>
  </channel>
</rss>

