<?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 Problem counting number of rows when using Filter with AND-logic in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-counting-number-of-rows-when-using-Filter-with-AND-logic/m-p/3239534#M119147</link>
    <description>&lt;P&gt;Hi. I have a table "PersonCertificates" with two columns:&lt;BR /&gt;&lt;BR /&gt;Person&amp;nbsp; &amp;nbsp;Certificate&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert1&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert2&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert3&lt;BR /&gt;MrB&amp;nbsp; &amp;nbsp;Cert1&lt;BR /&gt;MrB&amp;nbsp; &amp;nbsp;Cert2&lt;BR /&gt;MrC&amp;nbsp; &amp;nbsp;Cert3&lt;BR /&gt;&lt;BR /&gt;I have a slicer for Certificate and a table to list all Person(s).&lt;BR /&gt;&lt;BR /&gt;With the help of the two measures below I can apply AND-logic so the table only lists all persons that have all the selected certificates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_Number_of_selected_certificates := IF ( ISFILTERED ( 'PersonCertificates'[Certificate] ), COUNTROWS ( ALLSELECTED ( 'PersonCertificates'[Certificate] )), 0 )&lt;BR /&gt;_Person_Got_all_selected_certificates := IF ( [_Number_of_selected_certificates] = 0, 1, IF ( DISTINCTCOUNT ( 'PersonCertificates'[Certificate] ) = [_Number_of_selected_certificates], 1, 0 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use {_Person_Got_all_selected_certificates is 1} as a filter on the table that lists all Person's and this works fine. If I select Cert1 and Cert3 in the slicer I only get Mr A in the list - as expected. But I also want to calculate the number of persons listed in the table and I can't get this to work. I use this measure to calculate rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Number of person :=&lt;BR /&gt;var vPersonTable = SUMMARIZE ( 'PersonCertificates', 'PersonCertificates'[Person], "Person Got All selected certificates", [_Person_Got_all_selected_certificates] )&lt;BR /&gt;return&lt;BR /&gt;CALCULATE ( COUNTROWS ( vPersonTable ), FILTER ( vPersonTable, [Person Got All selected certificates] = 1 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure returns 3 when I select Cert 1 and Cert 3 but only shows Mr A in the table.&lt;/P&gt;&lt;P&gt;How can i get this calculation to work?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanx!&lt;/P&gt;&lt;P&gt;//Henrik&lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 06:49:30 GMT</pubDate>
    <dc:creator>BJ_TS</dc:creator>
    <dc:date>2023-05-17T06:49:30Z</dc:date>
    <item>
      <title>Problem counting number of rows when using Filter with AND-logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-counting-number-of-rows-when-using-Filter-with-AND-logic/m-p/3239534#M119147</link>
      <description>&lt;P&gt;Hi. I have a table "PersonCertificates" with two columns:&lt;BR /&gt;&lt;BR /&gt;Person&amp;nbsp; &amp;nbsp;Certificate&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert1&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert2&lt;BR /&gt;MrA&amp;nbsp; &amp;nbsp;Cert3&lt;BR /&gt;MrB&amp;nbsp; &amp;nbsp;Cert1&lt;BR /&gt;MrB&amp;nbsp; &amp;nbsp;Cert2&lt;BR /&gt;MrC&amp;nbsp; &amp;nbsp;Cert3&lt;BR /&gt;&lt;BR /&gt;I have a slicer for Certificate and a table to list all Person(s).&lt;BR /&gt;&lt;BR /&gt;With the help of the two measures below I can apply AND-logic so the table only lists all persons that have all the selected certificates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_Number_of_selected_certificates := IF ( ISFILTERED ( 'PersonCertificates'[Certificate] ), COUNTROWS ( ALLSELECTED ( 'PersonCertificates'[Certificate] )), 0 )&lt;BR /&gt;_Person_Got_all_selected_certificates := IF ( [_Number_of_selected_certificates] = 0, 1, IF ( DISTINCTCOUNT ( 'PersonCertificates'[Certificate] ) = [_Number_of_selected_certificates], 1, 0 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use {_Person_Got_all_selected_certificates is 1} as a filter on the table that lists all Person's and this works fine. If I select Cert1 and Cert3 in the slicer I only get Mr A in the list - as expected. But I also want to calculate the number of persons listed in the table and I can't get this to work. I use this measure to calculate rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Number of person :=&lt;BR /&gt;var vPersonTable = SUMMARIZE ( 'PersonCertificates', 'PersonCertificates'[Person], "Person Got All selected certificates", [_Person_Got_all_selected_certificates] )&lt;BR /&gt;return&lt;BR /&gt;CALCULATE ( COUNTROWS ( vPersonTable ), FILTER ( vPersonTable, [Person Got All selected certificates] = 1 ))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This measure returns 3 when I select Cert 1 and Cert 3 but only shows Mr A in the table.&lt;/P&gt;&lt;P&gt;How can i get this calculation to work?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanx!&lt;/P&gt;&lt;P&gt;//Henrik&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 06:49:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-counting-number-of-rows-when-using-Filter-with-AND-logic/m-p/3239534#M119147</guid>
      <dc:creator>BJ_TS</dc:creator>
      <dc:date>2023-05-17T06:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Problem counting number of rows when using Filter with AND-logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-counting-number-of-rows-when-using-Filter-with-AND-logic/m-p/3243507#M119402</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="344928" data-lia-user-login="BJ_TS" class="lia-mention lia-mention-user"&gt;BJ_TS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I have created a simple sample, please refer to it to see if it helps you.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CountNumber = 

var _a = SELECTCOLUMNS('Table 2',"Certificate",[Certificate])

return CALCULATE(DISTINCTCOUNT('Table'[Person]),FILTER(ALL('Table'),[Certificate] in _a))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Name = 

 var _a = SUMMARIZE(ALL('Table'),[Person],"Flag",CALCULATE(COUNT('Table'[Certificate]),FILTER(ALL('Table'),[Certificate] in SELECTCOLUMNS('Table 2',"Certificate",[Certificate])&amp;amp;&amp;amp;[Person]=EARLIER('Table'[Person]))))

 var _b = COUNTROWS(ALLSELECTED('Table 2'[Certificate]))

 return MAXX(FILTER(_a,[Person]=SELECTEDVALUE('Table'[Person])&amp;amp;&amp;amp;[Flag]=_b),[Person])&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;How to Get Your Question Answered Quickly&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;BR /&gt;Community Support Team _ Rongtie&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 03:16:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-counting-number-of-rows-when-using-Filter-with-AND-logic/m-p/3243507#M119402</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-19T03:16:57Z</dc:date>
    </item>
  </channel>
</rss>

