<?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: CountRows from related table, return 0 if unmatched in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3106100#M109468</link>
    <description>&lt;P&gt;The measure is just evaluated for the current filter context, but that changes for each data point, either a cell in a table or matrix or a point on a chart.&lt;/P&gt;
&lt;P&gt;As I understand it, SUMMARIZECOLUMNS generates the cross join of all values in the columns you put into the visual. It will then run any measures you add for each of these combinations. If all the measures return blank then that combination is not returned as part of the result set, but if any of the measures returns a non-blank value then it will be included.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 14:57:25 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2023-03-01T14:57:25Z</dc:date>
    <item>
      <title>CountRows from related table, return 0 if unmatched</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3103411#M109214</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I have the following tables and data (example scenario to demonstrate requirement):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Customer table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Invoice table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Product table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to implement a measure that gives me the total number of products on the invoice (by counting the number of rows).&amp;nbsp; Measure is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ProductCount1 = &lt;/SPAN&gt;&lt;SPAN&gt;COUNTROWS&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;InvoiceProducts&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;I have implemented the following measure, but it creates a cartesian product:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ProductCount = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; ProdCount = &lt;/SPAN&gt;&lt;SPAN&gt;COUNTROWS&lt;/SPAN&gt;&lt;SPAN&gt;(InvoiceProducts)&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt; &lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ISBLANK&lt;/SPAN&gt;&lt;SPAN&gt;(ProdCount),&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;,ProdCount)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Hoping someone could please explain why this is happening and how to resolve it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Ben.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 28 Feb 2023 11:07:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3103411#M109214</guid>
      <dc:creator>bhalicki</dc:creator>
      <dc:date>2023-02-28T11:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: CountRows from related table, return 0 if unmatched</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3103597#M109223</link>
      <description>&lt;P&gt;Its happening because the measure returns a non-blank result even for invalid combinations of customer and invoice. You can use&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num prods = SUMX( 'Invoice', COALESCE( COUNTROWS( RELATEDTABLE('Product')), 0))&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 28 Feb 2023 12:34:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3103597#M109223</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-02-28T12:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: CountRows from related table, return 0 if unmatched</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3104577#M109329</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt; , thank you for your help, your solution is perfect.&lt;BR /&gt;&lt;BR /&gt;Could you please explain why measures are evaulated for invalid combinations as well?&amp;nbsp; I always thought the measure would only be evaluated for the current filter context (in the example above, this would be InvoiceId and CustomerId).&lt;BR /&gt;&lt;BR /&gt;Every time I think I understand DAX, something completely changes my understanding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 20:02:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3104577#M109329</guid>
      <dc:creator>bhalicki</dc:creator>
      <dc:date>2023-02-28T20:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: CountRows from related table, return 0 if unmatched</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3106100#M109468</link>
      <description>&lt;P&gt;The measure is just evaluated for the current filter context, but that changes for each data point, either a cell in a table or matrix or a point on a chart.&lt;/P&gt;
&lt;P&gt;As I understand it, SUMMARIZECOLUMNS generates the cross join of all values in the columns you put into the visual. It will then run any measures you add for each of these combinations. If all the measures return blank then that combination is not returned as part of the result set, but if any of the measures returns a non-blank value then it will be included.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 14:57:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3106100#M109468</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-03-01T14:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: CountRows from related table, return 0 if unmatched</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3106600#M109531</link>
      <description>&lt;P&gt;Thanks &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt; , that makes sense.&amp;nbsp; Appreciate your help.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 20:26:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/CountRows-from-related-table-return-0-if-unmatched/m-p/3106600#M109531</guid>
      <dc:creator>bhalicki</dc:creator>
      <dc:date>2023-03-01T20:26:26Z</dc:date>
    </item>
  </channel>
</rss>

