<?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 DAX - IF Statement to Hold Last Value in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1812444#M38308</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to come up with a DAX formula for a calculated column "Last Index" that will return the current index if the NAME has changed from previous value, and hold the last index if the value has not changed.&amp;nbsp; Please see the example data below.&amp;nbsp; I have tried to make an if statement (IF current name &amp;lt;&amp;gt; previous name, index, __________)&amp;nbsp; but I'm getting stuck with the Else.&amp;nbsp; I've also tried LASTNONBLANK but I'm confused by it and getting errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Index&lt;/TD&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;Last Index&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Apr 2021 21:35:21 GMT</pubDate>
    <dc:creator>stalerik</dc:creator>
    <dc:date>2021-04-28T21:35:21Z</dc:date>
    <item>
      <title>DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1812444#M38308</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to come up with a DAX formula for a calculated column "Last Index" that will return the current index if the NAME has changed from previous value, and hold the last index if the value has not changed.&amp;nbsp; Please see the example data below.&amp;nbsp; I have tried to make an if statement (IF current name &amp;lt;&amp;gt; previous name, index, __________)&amp;nbsp; but I'm getting stuck with the Else.&amp;nbsp; I've also tried LASTNONBLANK but I'm confused by it and getting errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Index&lt;/TD&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;Last Index&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 21:35:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1812444#M38308</guid>
      <dc:creator>stalerik</dc:creator>
      <dc:date>2021-04-28T21:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1812549#M38316</link>
      <description>&lt;LI-CODE lang="csharp"&gt;[Last Index] = // calc column
var VeryFirstIndex = MIN( T[Index] )
var CurrIndex = T[Index]
var CurrName = T[Name]
var PrevIndex = CurrIndex - 1
var PrevName =
    MAXX(
        FILTER(
            T,
            T[Index] = PrevIndex
        ),
        T[Name]
    )
var Result =
    switch( true(),
    
        // If we're on the first row,
        // return the current index.
        CurrIndex = VeryFirstIndex, CurrIndex,
        
        // If the current name is same as
        // the prev name, return the value
        // of the index for the last different
        // name before this name plus 1.
        CurrName = PrevName,
            MAXX(
                FILTER(
                    T,
                    T[Name] &amp;lt;&amp;gt; CurrName
                    &amp;amp;&amp;amp;
                    T[Index] &amp;lt; CurrIndex
                ),
                T[Index]
            ) + VeryFirstIndex,
        
        // CurrName &amp;lt;&amp;gt; PrevName
        CurrIndex
    )
RETURN
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Apr 2021 00:17:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1812549#M38316</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-29T00:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1814104#M38361</link>
      <description>&lt;P&gt;This works great, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 12:21:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1814104#M38361</guid>
      <dc:creator>stalerik</dc:creator>
      <dc:date>2021-04-29T12:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833852#M39016</link>
      <description>&lt;P&gt;This calculated column works great for Import tables, but I have recently switched the data source to be Direct Query and this method does not work with the MAXX function.&amp;nbsp; Is there a method for performing the same calculations with a measure instead of a column, or some other way for Direct Query?&amp;nbsp; I have tried to modify it but I am getting stuck.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 13:56:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833852#M39016</guid>
      <dc:creator>stalerik</dc:creator>
      <dc:date>2021-05-10T13:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833868#M39017</link>
      <description>&lt;P&gt;Why can't you use a composite model so that you can mix DQ and Import?&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 14:09:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833868#M39017</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-05-10T14:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: DAX - IF Statement to Hold Last Value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833874#M39018</link>
      <description>&lt;P&gt;Since my source table was changed to Direct Query, I was thinking that it might not refresh correctly if I made the calculated table as Import.&amp;nbsp; I've usually only made models with one or the other, not a composite.&amp;nbsp; I will try a composite model like you suggest.&amp;nbsp; Thank you again for a quick response.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 14:16:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-IF-Statement-to-Hold-Last-Value/m-p/1833874#M39018</guid>
      <dc:creator>stalerik</dc:creator>
      <dc:date>2021-05-10T14:16:49Z</dc:date>
    </item>
  </channel>
</rss>

