<?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: Earliest Date Calculations in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/889022#M7779</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sure,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CALCULATED modifies Filter Context&lt;BR /&gt;TREATAS applies context on Table Date and filters it to only __minDate Value&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;KEEPFILTERS ensures the value is not calculated for 01/06/2019 as no new contracts there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could simplify this syntax&amp;nbsp; and remove TREATAS like below&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR __minDate = 
CALCULATE( 
    MIN( 'Table'[Date] ), 
    ALL( 'Table' ), 
    VALUES( 'Table'[Customer/Contract] ) 
)
RETURN 
CALCULATE(
    COUNTROWS( 'Table' ),
    KEEPFILTERS( 'Table'[Date] = __minDate )
) + 0&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Learn more about&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;TREATAS -&amp;nbsp;&lt;A href="https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/" target="_blank"&gt;https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/&lt;/A&gt;&lt;BR /&gt;KEEPFILTERS -&amp;nbsp;&lt;A href="https://www.sqlbi.com/articles/using-keepfilters-in-dax/" target="_blank"&gt;https://www.sqlbi.com/articles/using-keepfilters-in-dax/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2020 11:33:15 GMT</pubDate>
    <dc:creator>Mariusz</dc:creator>
    <dc:date>2020-01-03T11:33:15Z</dc:date>
    <item>
      <title>Earliest Date Calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888895#M7775</link>
      <description>&lt;P&gt;I need a quick bit of help on Power BI. Consider a table showing Customer/Contracts and the dates those contracts were signed – a bit like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Customer/Contract&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sky-ABC123&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2018-06&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sky-ABC124&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2018-06&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sky-ABC123&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2019-06&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that we need to identify how many new were signed in each month.&amp;nbsp;&amp;nbsp;&amp;nbsp; So in the above table Sky signed 2 new contracts in June 2018 but zero &lt;STRONG&gt;new&lt;/STRONG&gt; ones in June 2019 as that is a renewal.&amp;nbsp; Required output is below.&amp;nbsp; &amp;nbsp;&amp;nbsp;Really we just needs a way to distinguish renewals from new – which can be done by finding the earliest date for each distinct customer/contract.&amp;nbsp; &amp;nbsp;I could manage this in SQL easily enough but have no idea how to do it in PowerBI.&amp;nbsp; Can someone guide how to do this in PowerBI?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Month&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;New Contracts&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2018-06&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2019-06&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 03 Jan 2020 09:53:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888895#M7775</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-03T09:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Earliest Date Calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888927#M7776</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
VAR __minDate = 
CALCULATE( 
    MIN( 'Table'[Date] ), 
    ALL( 'Table' ), 
    VALUES( 'Table'[Customer/Contract] ) 
)
RETURN 
CALCULATE(
    COUNTROWS( 'Table' ),
    KEEPFILTERS( TREATAS( { __minDate }, 'Table'[Date] ) )
) + 0&lt;/LI-CODE&gt;
&lt;DIV&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 10:26:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888927#M7776</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2020-01-03T10:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Earliest Date Calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888939#M7777</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81408" data-lia-user-login="Mariusz" class="lia-mention lia-mention-user"&gt;Mariusz&lt;/a&gt;&amp;nbsp; Thanks for your quick reply, Could you please explain little bit in details how we are calcualting this measure, especially this part of the formula, I am quite new in DAX and trying to understand what does this part of DAX is:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;CALCULATE(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNTROWS( 'Table' ),&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; KEEPFILTERS( TREATAS( { __minDate }, 'Table'[Date] ) )&lt;BR /&gt;) + 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 10:36:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/888939#M7777</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-03T10:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Earliest Date Calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/889022#M7779</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sure,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CALCULATED modifies Filter Context&lt;BR /&gt;TREATAS applies context on Table Date and filters it to only __minDate Value&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;KEEPFILTERS ensures the value is not calculated for 01/06/2019 as no new contracts there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could simplify this syntax&amp;nbsp; and remove TREATAS like below&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR __minDate = 
CALCULATE( 
    MIN( 'Table'[Date] ), 
    ALL( 'Table' ), 
    VALUES( 'Table'[Customer/Contract] ) 
)
RETURN 
CALCULATE(
    COUNTROWS( 'Table' ),
    KEEPFILTERS( 'Table'[Date] = __minDate )
) + 0&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Learn more about&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;TREATAS -&amp;nbsp;&lt;A href="https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/" target="_blank"&gt;https://www.sqlbi.com/blog/marco/2017/11/25/using-treatas-in-place-of-in-in-dax/&lt;/A&gt;&lt;BR /&gt;KEEPFILTERS -&amp;nbsp;&lt;A href="https://www.sqlbi.com/articles/using-keepfilters-in-dax/" target="_blank"&gt;https://www.sqlbi.com/articles/using-keepfilters-in-dax/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 11:33:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/889022#M7779</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2020-01-03T11:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Earliest Date Calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/889043#M7781</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81408" data-lia-user-login="Mariusz" class="lia-mention lia-mention-user"&gt;Mariusz&lt;/a&gt;Thanks a lot for your extended help. I appreciate your prompt reply and taking out time to answer it.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2020 11:44:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Earliest-Date-Calculations/m-p/889043#M7781</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-03T11:44:53Z</dc:date>
    </item>
  </channel>
</rss>

