<?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 to calculate distinctcount of ID of previous month and current month based on filter selection. in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3498967#M134110</link>
    <description>&lt;P&gt;Hi everyone, I want to calculate distinct count of product ID based on the filter selection of date.&lt;BR /&gt;Lets say, I select month Sept in the date slicer. I want to show the distinct count of products of the selected month and the previous month of it. And it has to be filtered with status A only. Which I can add it in the filter pane.&lt;BR /&gt;I wrote the following dax but I am not able to get the result.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;XYZ = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'r Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DISTINCTCOUNT&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;[product_id]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'Master Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I have attached the data as well for the reference. Date format is same as it is here.&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Please suggest an alternative way or share your thoughts on this. Thank you&amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="403667" data-lia-user-login="123abc" class="lia-mention lia-mention-user"&gt;123abc&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 12:58:16 GMT</pubDate>
    <dc:creator>prv_1401</dc:creator>
    <dc:date>2023-10-26T12:58:16Z</dc:date>
    <item>
      <title>Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3498967#M134110</link>
      <description>&lt;P&gt;Hi everyone, I want to calculate distinct count of product ID based on the filter selection of date.&lt;BR /&gt;Lets say, I select month Sept in the date slicer. I want to show the distinct count of products of the selected month and the previous month of it. And it has to be filtered with status A only. Which I can add it in the filter pane.&lt;BR /&gt;I wrote the following dax but I am not able to get the result.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;XYZ = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'r Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DISTINCTCOUNT&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;[product_id]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;' Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;'Master Data'&lt;/SPAN&gt;&lt;SPAN&gt;[date]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;A&lt;/SPAN&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I have attached the data as well for the reference. Date format is same as it is here.&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Please suggest an alternative way or share your thoughts on this. Thank you&amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="403667" data-lia-user-login="123abc" class="lia-mention lia-mention-user"&gt;123abc&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 12:58:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3498967#M134110</guid>
      <dc:creator>prv_1401</dc:creator>
      <dc:date>2023-10-26T12:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499002#M134112</link>
      <description>&lt;P&gt;Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue. &lt;BR /&gt;If you are unsure how to do that please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;If you want to get answers faster please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:04:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499002#M134112</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-10-26T13:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499052#M134117</link>
      <description>&lt;P&gt;&lt;SPAN&gt;You can achieve this by modifying your DAX calculation as follows:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;XYZ =&lt;BR /&gt;VAR SelectedDate = SELECTEDVALUE('r Data'[date])&lt;BR /&gt;VAR PreviousMonth = SelectedDate - 1&lt;BR /&gt;RETURN&lt;BR /&gt;CALCULATE(&lt;BR /&gt;DISTINCTCOUNT(' Data'[product_id]),&lt;BR /&gt;FILTER(' Data', ' Data'[date] = SelectedDate || ' Data'[date] = PreviousMonth),&lt;BR /&gt;' Data'[status] = "A"&lt;BR /&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:21:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499052#M134117</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2023-10-26T13:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499080#M134122</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;, this is sample data with output. Can you please check the dax and let me know whats the issue in it ?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:32:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499080#M134122</guid>
      <dc:creator>prv_1401</dc:creator>
      <dc:date>2023-10-26T13:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499104#M134125</link>
      <description>&lt;P&gt;second request:&amp;nbsp;Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue. &lt;BR /&gt;If you are unsure how to do that please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;If you want to get answers faster please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:41:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3499104#M134125</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-10-26T13:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dax to calculate distinctcount of ID of previous month and current month based on filter selection.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3506368#M134507</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="435159" data-lia-user-login="prv_1401" class="lia-mention lia-mention-user"&gt;prv_1401&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create calculated table.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Date =
var _table1=
CALENDAR(
    DATE(2001,1,1),
    DATE(2001,12,31))
return
ADDCOLUMNS(
    _table1,"Date_format",FORMAT([Date],"yy")&amp;amp;"-"&amp;amp;FORMAT([Date],"mmm")
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;2. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure =
var _selectdate=SELECTEDVALUE('Date'[Date_format])
var _selectstatus=SELECTEDVALUE('Master Data'[Status])
var _date1=MINX(FILTER(ALL('Date'),'Date'[Date_format]=_selectdate),[Date])
var _date2=DATE(YEAR(_date1),MONTH(_date1)-1,DAY(_date1))
var _lastmonth=MONTH(_date2)
var _currentmonth=MONTH(_date1)
return
CALCULATE(
    DISTINCTCOUNT('Master Data'[Product ID]),
    FILTER(ALL('Master Data'),
    'Master Data'[Month ID] in {_lastmonth,_currentmonth} &amp;amp;&amp;amp;'Master Data'[Status]=_selectstatus))&lt;/LI-CODE&gt;
&lt;P&gt;3. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 06:17:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-to-calculate-distinctcount-of-ID-of-previous-month-and/m-p/3506368#M134507</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-10-31T06:17:28Z</dc:date>
    </item>
  </channel>
</rss>

