<?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: take the different between top 2 days in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164838#M50127</link>
    <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please check now: You can remove the last zero and replace it with blank if you do not want to see the other dates.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top 2 Diff = 
VAR __DATES =  TOPN( 2 , CALCULATETABLE( VALUES(Data[CTP Date]) ,  ALLEXCEPT(Data,Data[PeggingKey] )) , Data[CTP Date])
VAR __MIN = MINX(  __DATES, Data[CTP Date] )
VAR __MAX = MAXX(  __DATES, Data[CTP Date] )
VAR __CURRENTDATE = MAX(Data[CTP Date])
RETURN
IF(
    NOT(HASONEVALUE(Data[PeggingKey])) , 
    BLANK(), 
    IF ( __CURRENTDATE IN {__MAX , __MIN},
        DATEDIFF( __MIN , __MAX,   DAY ),
        0
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 31 Oct 2021 12:23:12 GMT</pubDate>
    <dc:creator>Fowmy</dc:creator>
    <dc:date>2021-10-31T12:23:12Z</dc:date>
    <item>
      <title>take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164787#M50118</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me to resolve this query in DAX.&lt;BR /&gt;&lt;BR /&gt;As per below image I want to take the difference between top 2 dates for each pegging key as a measure. Answer should changed based on filters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Power BI File attched here&lt;BR /&gt;&lt;A href="https://drive.google.com/file/d/1PThqaYQGn0RvsOdNKwPsVYoC0eYuAJmW/view?usp=sharing" target="_blank"&gt;https://drive.google.com/file/d/1PThqaYQGn0RvsOdNKwPsVYoC0eYuAJmW/view?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 10:07:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164787#M50118</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T10:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164789#M50119</link>
      <description>&lt;P&gt;&amp;nbsp;Should be like this, Also better not to iterate over whole table and just iterate over only required columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 10:12:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164789#M50119</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T10:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164792#M50120</link>
      <description>&lt;P&gt;This is my Current Calc&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;date gap = 
var topdate_1 = 
    CALCULATE(
        MAX('data'[CTP Date]),
        ALLEXCEPT('data','data'[PeggingKey])
    )
var Rank_answer = 
    RANKX(
        ALL('data'[PeggingKey]),
        MAX('data'[CTP Date]),,
        DESC
    )
var Topdate_3 = 
    CALCULATE(
        MAX('data'[CTP Date]),
        FILTER(
            'data',
            Rank_answer = 2
        )
    )
return
DATEDIFF(topdate_1,Topdate_3,DAY)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 31 Oct 2021 10:48:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164792#M50120</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T10:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164795#M50121</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You can use this meaure:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top 2 Diff = 
VAR __DATES = TOPN( 2 , VALUES(Data[CTP Date]) , Data[CTP Date])
RETURN
IF(
    HASONEVALUE(Data[PeggingKey]),
    DATEDIFF(
        MINX(  __DATES, Data[CTP Date] ),
        MAXX( __DATES , Data[CTP Date] ),
        DAY
    )

)&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 31 Oct 2021 11:13:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164795#M50121</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2021-10-31T11:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164802#M50122</link>
      <description>&lt;P&gt;Thanks this working with just Pegging key. When I bring CTP column to this table results getting wrong.&amp;nbsp; Could you please fix that as well.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 11:24:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164802#M50122</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T11:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164815#M50123</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Not sure why you need to bring in the CTP date here. So, how do you want the difference to be show ? only on the maximum date per Pegging Key and others blank ?&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 11:53:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164815#M50123</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2021-10-31T11:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164828#M50125</link>
      <description>&lt;P&gt;Yes, Because this is part of full table. Each pegging key have multiple CTP dates. So I want to see the datediff for top 2 CTP dates next to CTP date&lt;img /&gt; and other can be blank or zero as well.&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 12:16:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164828#M50125</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T12:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164838#M50127</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Please check now: You can remove the last zero and replace it with blank if you do not want to see the other dates.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top 2 Diff = 
VAR __DATES =  TOPN( 2 , CALCULATETABLE( VALUES(Data[CTP Date]) ,  ALLEXCEPT(Data,Data[PeggingKey] )) , Data[CTP Date])
VAR __MIN = MINX(  __DATES, Data[CTP Date] )
VAR __MAX = MAXX(  __DATES, Data[CTP Date] )
VAR __CURRENTDATE = MAX(Data[CTP Date])
RETURN
IF(
    NOT(HASONEVALUE(Data[PeggingKey])) , 
    BLANK(), 
    IF ( __CURRENTDATE IN {__MAX , __MIN},
        DATEDIFF( __MIN , __MAX,   DAY ),
        0
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 12:23:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164838#M50127</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2021-10-31T12:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164866#M50131</link>
      <description>&lt;P&gt;Thank you very much Fowmy. This working so far. Because I have sent just sample data to you. But when I add more feilds like CTP date the results dissapear. Any suggestion to fix that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 13:00:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164866#M50131</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-31T13:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164869#M50132</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;How did you send the file? I am not sure about the issue you are facing, can you save it in one drive or google drive share the link here?&amp;nbsp; clearly explain where you are not getting the result correct.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Oct 2021 13:23:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2164869#M50132</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2021-10-31T13:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: take the different between top 2 days</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2167562#M50268</link>
      <description>&lt;P&gt;The data set is so big I can't share that data. So I will accpet this as the solution. Thanks for the support.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 05:28:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/take-the-different-between-top-2-days/m-p/2167562#M50268</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-02T05:28:50Z</dc:date>
    </item>
  </channel>
</rss>

