<?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: Counting dimension's attribute distinct values in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027530#M13413</link>
    <description>I know all of this. But the original task was to calculate the number of distinct suppliers that made at least one purchase.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
    <pubDate>Wed, 15 Apr 2020 14:19:15 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-04-15T14:19:15Z</dc:date>
    <item>
      <title>Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024892#M13316</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I need your help. I have to count the distinct suppliers from witch I made at least a purchase, given a certain filter context.&lt;/P&gt;&lt;P&gt;Since the relationship between the dimension table of the suppliers ('Fornitori intestatari') and the fact table of the purchases ('Acquisti') is set as a standard one-way filter direction, one-to-many:&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;&lt;P&gt;I was pretty sure that a dax formula like this one was necessary, levereging a CROSSFILTER() function or similar to obtain the distinct count of suppliers, filtered by the purchases fact table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Fornitori con fatturato =&lt;BR /&gt;VAR DatiFatturato = &lt;FONT&gt;CALCULATETABLE('Acquisti';'Acquisti'[Flag fatturato]=1)&lt;/FONT&gt;&lt;BR /&gt;RETURN&lt;BR /&gt;COUNTROWS(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALCULATETABLE (&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES('Fornitori intestatari'[Fornitore - Descrizione]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DatiFatturato; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CROSSFILTER ('Acquisti'[K_CodCli]; 'Fornitori intestatari'[K_CodCli]; BOTH)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and it works, indeed.&lt;/P&gt;&lt;P&gt;What I can't explain to myself is that this ultra simplified version of the expression seems to be working fine, as well:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;FONT&gt;Fornitori con fatturato =&lt;BR /&gt;VAR DatiFatturato = CALCULATETABLE('Acquisti';'Acquisti'[Flag fatturato]=1)&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT&gt;RETURN&lt;BR /&gt;CALCULATE(DISTINCTCOUNT('Fornitori intestatari'[Fornitore - Descrizione]); DatiFatturato)&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone explain me why? My hypothesis is that the DISTINCTCOUNT is working on what here (&lt;FONT&gt;&lt;A href="https://www.sqlbi.com/articles/expanded-tables-in-dax/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/articles/expanded-tables-in-dax/&lt;/A&gt;&lt;/FONT&gt;) is called 'the expanded version' of the fact table 'Acquisti', instead of the 'physical' dimension table 'Fornitori intestatari', that is to say a sort of SELECT * FROM 'Aquisti' LEFT JOIN 'Fornitori intestatari', if I correctly understood.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If so, is this syntax safe, or is the first one better?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 13:31:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024892#M13316</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-14T13:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024913#M13317</link>
      <description>Can you just switch the relationship to Both?</description>
      <pubDate>Tue, 14 Apr 2020 13:39:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024913#M13317</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-04-14T13:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024974#M13319</link>
      <description>&lt;P&gt;The relationship has to be mono-directional. The point is that I would excpect the second formula expression to be working only after setting the relationship type to 'both', while it's working properly even with the relationship set to 'single'...&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 13:55:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1024974#M13319</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-14T13:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027316#M13389</link>
      <description>It's rather simple. When you do distinctcount( Fact[DimKey] ), you are just calculating the number of different DimKey's in your fact table in the rows that are visible in the current context. No magic. This simple measure applied to your model does exactly what you want:&lt;BR /&gt;&lt;BR /&gt;I have to count the distinct suppliers from witch I made at least a purchase, given a certain filter context.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Wed, 15 Apr 2020 12:42:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027316#M13389</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T12:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027354#M13390</link>
      <description>&lt;P&gt;I'm not. I'm doing &lt;SPAN&gt;DISTINCTCOUNT( Dimension[DimAttribute] ), over a single-way relationship, and it's working the same as the CROSSFILTER() version of the formula.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 13:00:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027354#M13390</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T13:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027361#M13391</link>
      <description>In this case (which I missed) expanded tables are at work.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Wed, 15 Apr 2020 13:03:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027361#M13391</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T13:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027364#M13392</link>
      <description>But you should not use this technique as it can be slow and resource intensive. Use what I did above.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Wed, 15 Apr 2020 13:04:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027364#M13392</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T13:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027404#M13396</link>
      <description>&lt;P&gt;Ok, but you may have to count the distinct number of dim attributes that don't have the same granularity of the dimension's key, e.g. the supplier's country. The point is that filter propagation in DAX is still not entirely clear to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Bye!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 13:22:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027404#M13396</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T13:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027427#M13400</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;The reason for&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR DatiFatturato = CALCULATETABLE('Acquisti';'Acquisti'[Flag fatturato]=1) &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;not being able to propagate the filters to&amp;nbsp;'Fornitori intestatari' is that&amp;nbsp;'Acquisti' within CALCULATETABLE is not expanded any more so it does not include&amp;nbsp;'Fornitori intestatari' in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try the below if the granularity of&amp;nbsp;'Fornitori intestatari'[Fornitore - Descrizione] is different to&amp;nbsp;'Fornitori intestatari'[K_CodCli]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Fornitori con fatturato =
CALCULATE(
    DISTINCTCOUNT( 'Fornitori intestatari'[Fornitore - Descrizione] );
    CROSSFILTER( 'Acquisti'[K_CodCli]; 'Fornitori intestatari'[K_CodCli]; BOTH );
    'Acquisti'[Flag fatturato] = 1
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="71" data-lia-user-login="AlbertoFerrari" class="lia-mention lia-mention-user"&gt;AlbertoFerrari&lt;/a&gt;&amp;nbsp;Please correct if I'm wrong, or elaborate so we can understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&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;BR /&gt;&lt;BR /&gt;Please feel free to connect with me.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/mariusz-repczynski-065a7362/" target="_blank" rel="noopener"&gt; LinkedIn &lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 13:37:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027427#M13400</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2020-04-15T13:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027452#M13402</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expanded version of Acquisti actually contains the full Fornitori table.&lt;/P&gt;&lt;P&gt;Therefore, if you use Acquisti as a filter argument in CALCULATE, you are filtering Fornitori too.&amp;nbsp;CROSSFILTER is useless in this case. You could obtain the same performing a DISTINCTCOUNT, use CROSSFILTER avoiding the variable at all.&lt;/P&gt;&lt;P&gt;With that said, I would use something easier to read, like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;COUNTROWS ( SUMMARIZE ( Acquisti, Fornitori[Fornitore - Descrizione] ) )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did not check performance, but it shouldn't be too bad, and definitely easier to read.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 13:46:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027452#M13402</guid>
      <dc:creator>AlbertoFerrari</dc:creator>
      <dc:date>2020-04-15T13:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027488#M13408</link>
      <description>&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="71" data-lia-user-login="AlbertoFerrari" class="lia-mention lia-mention-user"&gt;AlbertoFerrari&lt;/a&gt;, would a simple DISTINCTCOUNT( Fact[DimKey] ) not be enough?&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Wed, 15 Apr 2020 14:03:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027488#M13408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T14:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027512#M13411</link>
      <description>&lt;P&gt;Only if you are counting the keys. If an attribute of the dimension is not unique (think at city, name, gender), then you need to use either SUMMARIZE or the expanded table. Or Bidirectional filtering... but you know, bidirectional cross-filter is like opening the door of Hell to say "Hello". Fascinating... but better stay away &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 14:13:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027512#M13411</guid>
      <dc:creator>AlbertoFerrari</dc:creator>
      <dc:date>2020-04-15T14:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027530#M13413</link>
      <description>I know all of this. But the original task was to calculate the number of distinct suppliers that made at least one purchase.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Wed, 15 Apr 2020 14:19:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027530#M13413</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T14:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027554#M13414</link>
      <description>&lt;P&gt;Yep, you're right. Looked to me that the goal was understanding what's happening underneath, and not just to make the measure work.&lt;/P&gt;&lt;P&gt;Anyway, good chat, this is what really matters. Apparently, there was no problem, but we had a good time discussing it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 14:24:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027554#M13414</guid>
      <dc:creator>AlbertoFerrari</dc:creator>
      <dc:date>2020-04-15T14:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027563#M13415</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="71" data-lia-user-login="AlbertoFerrari" class="lia-mention lia-mention-user"&gt;AlbertoFerrari&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for jumping in and clarifying.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Mariusz&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 14:26:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027563#M13415</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2020-04-15T14:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting dimension's attribute distinct values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027588#M13416</link>
      <description>&lt;P&gt;Yes, maybe the example was misleading, but the purpose was to understand a little bit more what happens behind the curtain...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all guys!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 14:31:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Counting-dimension-s-attribute-distinct-values/m-p/1027588#M13416</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-15T14:31:26Z</dc:date>
    </item>
  </channel>
</rss>

