<?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: Calculate the difference between values not blank in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/860242#M6947</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;Try this: The code looks longer than it is.&amp;nbsp; Merely duplicate for each different month, in this case Jan and February. Will point out the high non blank value in January is not the last date, whereas the last nonblank value in February is the last date in February, but it is not the highest value, which is correct.&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;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;are nice too.&lt;BR /&gt;Nathaniel&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LastNonBlank Value of Feb - Jan =
VAR LastNonBlankDateJanuary =
    CALCULATE (
        MAX ( myTable[Date] ),
        FILTER (
            ALL ( myTable ),
            myTable[Date] &amp;lt;= DATE ( 2019, 1, 31 )
                &amp;amp;&amp;amp; myTable[Date] &amp;gt;= DATE ( 2019, 1, 1 )
                &amp;amp;&amp;amp; myTable[Value] &amp;lt;&amp;gt; 0
        )
    )
VAR _January =
    CALCULATE (
        SUM ( myTable[Value] ),
        FILTER ( ALL ( myTable ), myTable[Date] = LastNonBlankDateJanuary )
    )
VAR LastNonBlankDateFebruary =
    CALCULATE (
        MAX ( myTable[Date] ),
        FILTER (
            ALL ( myTable ),
            myTable[Date] &amp;lt;= DATE ( 2019, 2, 28 )
                &amp;amp;&amp;amp; myTable[Date] &amp;gt;= DATE ( 2019, 2, 1 )
                &amp;amp;&amp;amp; myTable[Value] &amp;lt;&amp;gt; 0
        )
    )
VAR _February =
    CALCULATE (
        SUM ( myTable[Value] ),
        FILTER ( ALL ( myTable ), myTable[Date] = LastNonBlankDateFebruary )
    )
RETURN
    _February - _January&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Nov 2019 03:50:45 GMT</pubDate>
    <dc:creator>Nathaniel_C</dc:creator>
    <dc:date>2019-11-29T03:50:45Z</dc:date>
    <item>
      <title>Calculate the difference between values not blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/860192#M6946</link>
      <description>&lt;P&gt;Hi Guys,&lt;BR /&gt;I need to calculate the difference between column (3)&lt;/P&gt;&lt;P&gt;Last value not blank this month&amp;nbsp; - Last value not blank before this moth&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 02:50:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/860192#M6946</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-29T02:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the difference between values not blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/860242#M6947</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;Try this: The code looks longer than it is.&amp;nbsp; Merely duplicate for each different month, in this case Jan and February. Will point out the high non blank value in January is not the last date, whereas the last nonblank value in February is the last date in February, but it is not the highest value, which is correct.&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;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;are nice too.&lt;BR /&gt;Nathaniel&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LastNonBlank Value of Feb - Jan =
VAR LastNonBlankDateJanuary =
    CALCULATE (
        MAX ( myTable[Date] ),
        FILTER (
            ALL ( myTable ),
            myTable[Date] &amp;lt;= DATE ( 2019, 1, 31 )
                &amp;amp;&amp;amp; myTable[Date] &amp;gt;= DATE ( 2019, 1, 1 )
                &amp;amp;&amp;amp; myTable[Value] &amp;lt;&amp;gt; 0
        )
    )
VAR _January =
    CALCULATE (
        SUM ( myTable[Value] ),
        FILTER ( ALL ( myTable ), myTable[Date] = LastNonBlankDateJanuary )
    )
VAR LastNonBlankDateFebruary =
    CALCULATE (
        MAX ( myTable[Date] ),
        FILTER (
            ALL ( myTable ),
            myTable[Date] &amp;lt;= DATE ( 2019, 2, 28 )
                &amp;amp;&amp;amp; myTable[Date] &amp;gt;= DATE ( 2019, 2, 1 )
                &amp;amp;&amp;amp; myTable[Value] &amp;lt;&amp;gt; 0
        )
    )
VAR _February =
    CALCULATE (
        SUM ( myTable[Value] ),
        FILTER ( ALL ( myTable ), myTable[Date] = LastNonBlankDateFebruary )
    )
RETURN
    _February - _January&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 03:50:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/860242#M6947</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2019-11-29T03:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the difference between values not blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/864861#M7036</link>
      <description>&lt;P&gt;&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;thanks &amp;nbsp;for the help, I need a flexible solution.&lt;BR /&gt;I developed the solution below, but this calculate is very slow:&lt;BR /&gt;Do you know a form of optimizer?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Delta KM com VAR = 
//------------------------------------------------------------------------
SUMX(
    VALUES(Diesel[Chave]);
 //-------------------Primeira Quilomatragem----------------------------------------------
VAR Primeiro_KM = 
    CALCULATE(
        if(
        CALCULATE(
        max(Diesel[Quilometragem ou Horas]);
        FILTER(
            all(Diesel);
            Diesel[Data da Transacao] &amp;lt; min(Diesel[Data da Transacao])&amp;amp;&amp;amp;
            Diesel[Quilometragem ou Horas] &amp;lt;&amp;gt; BLANK()&amp;amp;&amp;amp;
            Diesel[Inventario] = max(Diesel[Inventario])
        )
    ) =BLANK();
        CALCULATE(
            max(Diesel[Quilometragem ou Horas]);
            FILTER(
                all(Diesel);
                Diesel[Data da Transacao] &amp;lt;= min(Diesel[Data da Transacao])&amp;amp;&amp;amp;
                Diesel[Quilometragem ou Horas] &amp;lt;&amp;gt; BLANK()&amp;amp;&amp;amp;
                Diesel[Inventario] = max(Diesel[Inventario])
            )
        );
        CALCULATE(
            max(Diesel[Quilometragem ou Horas]);
            FILTER(
                all(Diesel);
                Diesel[Data da Transacao] &amp;lt; min(Diesel[Data da Transacao])&amp;amp;&amp;amp;
                Diesel[Quilometragem ou Horas] &amp;lt;&amp;gt; BLANK()&amp;amp;&amp;amp;
                Diesel[Inventario] = max(Diesel[Inventario])
            )
        )
    )
)
//------------------------Ultima Quilomatragem----------------------------------------------------
    VAR Ultimo_KM = 
    CALCULATE(
        CALCULATE(
        max(Diesel[Quilometragem ou Horas]);

            LASTNONBLANK(
                Diesel[Data da Transacao];
                CALCULATE(max(Diesel[Quilometragem ou Horas])
                )
            )   
)
    )
    return
 //------------------------------------------------------------------------\

    Ultimo_KM-Primeiro_KM
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 11:55:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-the-difference-between-values-not-blank/m-p/864861#M7036</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-12-04T11:55:08Z</dc:date>
    </item>
  </channel>
</rss>

