<?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 Difference between CALCULATE(..., &amp;lt;clause&amp;gt;) vs CALCULATE(..., FILTER(..., &amp;lt;clause&amp;gt;)) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273368#M169520</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking to verify my understanding on how CALCULATE and FILTER functions work. In this dummy example, I have 2 tables with a single direction filter.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I attempt to perform a DAX computation (I.e. DISTINCTCOUNT(Country[Country])) it seems that wrapping up the clause in FILTER(...) creates an alternative filtering direction. Examples below:&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;V3's computation is similar to the example in MS doc's for CROSSFILTER:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/dax/crossfilter-function-dax" target="_blank"&gt;https://learn.microsoft.com/en-us/dax/crossfilter-function-dax&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TLDR: From my understanding, since a filtering direction from sales to country is not enabled, &lt;U&gt;both measures V1 and V2 should return 4;&lt;FONT color="#FF0000"&gt; however, V2 returns 1&lt;/FONT&gt;&lt;/U&gt;. On the other hand, V3 enforces cross-filtering from&amp;nbsp;sales to country, thus giving the answer 1 as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding of how CALCULATE and FILTER might be wrong and I would appreciate if anyone could offer some inputs&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2024 04:10:43 GMT</pubDate>
    <dc:creator>DarylK_MA</dc:creator>
    <dc:date>2024-11-07T04:10:43Z</dc:date>
    <item>
      <title>Difference between CALCULATE(..., &lt;clause&gt;) vs CALCULATE(..., FILTER(..., &lt;clause&gt;))</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273368#M169520</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking to verify my understanding on how CALCULATE and FILTER functions work. In this dummy example, I have 2 tables with a single direction filter.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I attempt to perform a DAX computation (I.e. DISTINCTCOUNT(Country[Country])) it seems that wrapping up the clause in FILTER(...) creates an alternative filtering direction. Examples below:&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;V3's computation is similar to the example in MS doc's for CROSSFILTER:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/dax/crossfilter-function-dax" target="_blank"&gt;https://learn.microsoft.com/en-us/dax/crossfilter-function-dax&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TLDR: From my understanding, since a filtering direction from sales to country is not enabled, &lt;U&gt;both measures V1 and V2 should return 4;&lt;FONT color="#FF0000"&gt; however, V2 returns 1&lt;/FONT&gt;&lt;/U&gt;. On the other hand, V3 enforces cross-filtering from&amp;nbsp;sales to country, thus giving the answer 1 as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding of how CALCULATE and FILTER might be wrong and I would appreciate if anyone could offer some inputs&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 04:10:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273368#M169520</guid>
      <dc:creator>DarylK_MA</dc:creator>
      <dc:date>2024-11-07T04:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between CALCULATE(..., &lt;clause&gt;) vs CALCULATE(..., FILTER(..., &lt;clause&gt;))</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273396#M169521</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="478731" data-lia-user-login="DarylK_MA" class="lia-mention lia-mention-user"&gt;DarylK_MA&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've raised a good question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The immediate answer to the question of why V2 appears to apply a filter from &lt;STRONG&gt;Sales&lt;/STRONG&gt; to &lt;STRONG&gt;Country&lt;/STRONG&gt; (i.e. the opposite of the relationship crossfilter direction) is that when physical model tables are provided as filter arguments within CALCULATE (whether or not enclosed in FILTER or CALCULATETABLE), they are treated as expanded tables which include all columns of tables on the 1-side of many-to-1 relationships from the table referenced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example, when &lt;STRONG&gt;FILTER ( Sales, ... )&lt;/STRONG&gt; is included as a filter argument within CALCULATE, the filtered expanded&amp;nbsp;&lt;STRONG&gt;Sales&lt;/STRONG&gt; table includes all columns of related tables including &lt;STRONG&gt;Country&lt;/STRONG&gt; (and any others, e.g. &lt;STRONG&gt;'Date'&lt;/STRONG&gt;). This often leads to unexpected results, since the outcome depends on all tables related to the table referenced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your V1 &amp;amp; V3 measures, however, apply filters on columns, so the behaviour is as you would expect. A filter on a single column cannot be converted into an expanded table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of this behaviour with expanded tables, this article recommends filtering columns, not tables (and I would concur as a general rule):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlbi.com/articles/filter-columns-not-tables-in-dax/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/articles/filter-columns-not-tables-in-dax/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some other articles I suggest reading on this subject:&lt;/P&gt;
&lt;P&gt;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://mdxdax.blogspot.com/2011/03/logic-behind-magic-of-dax-cross-table.html" target="_blank" rel="noopener"&gt;https://mdxdax.blogspot.com/2011/03/logic-behind-magic-of-dax-cross-table.html&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;(classic post from Jeffrey Wang)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlbi.com/articles/filter-arguments-in-calculate/" target="_blank" rel="noopener"&gt;https://www.sqlbi.com/articles/filter-arguments-in-calculate/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This article on Related Distinct Count may also be of interest:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.daxpatterns.com/related-distinct-count/" target="_blank" rel="noopener"&gt;https://www.daxpatterns.com/related-distinct-count/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 04:55:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273396#M169521</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2024-11-07T04:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between CALCULATE(..., &lt;clause&gt;) vs CALCULATE(..., FILTER(..., &lt;clause&gt;))</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273402#M169522</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="478731" data-lia-user-login="DarylK_MA" class="lia-mention lia-mention-user"&gt;DarylK_MA&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It sounds like you have a good grasp on the concepts! CALCULATE and FILTER can indeed behave a bit differently when it comes to cross-filtering directions, especially when you have a single-direction relationship in your model.&lt;BR /&gt;Here in the above case,&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;V1&lt;/STRONG&gt;: Returns 4 because there's no enforced cross-filtering direction, so only the initial filtering from the Country table is considered.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;V2&lt;/STRONG&gt;: Returns 1 because using FILTER within CALCULATE indirectly introduces a temporary cross-filtering effect.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;V3&lt;/STRONG&gt;: Explicitly enforces bidirectional filtering using CROSSFILTER, yielding 1 as well.&lt;BR /&gt;So what I think is,&lt;UL&gt;&lt;LI&gt;Using &lt;STRONG&gt;FILTER&amp;nbsp;&lt;/STRONG&gt;within &lt;STRONG&gt;CALCULATE&amp;nbsp;&lt;/STRONG&gt;can implicitly create row context transitions and alternative cross-filtering.&lt;/LI&gt;&lt;LI&gt;For precise control, use &lt;STRONG&gt;CROSSFILTER&lt;/STRONG&gt; when you need a bidirectional filter for specific calculations, rather than relying on implicit behavior from FILTER.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution, this will help others!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If my response(s) assisted you in any way, don't forget to drop me a &lt;STRONG&gt;"Kudos"&lt;/STRONG&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;BR /&gt;Poojara&lt;BR /&gt;Data Analyst | MSBI Developer | Power BI Consultant&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 09:20:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Difference-between-CALCULATE-lt-clause-gt-vs-CALCULATE-FILTER-lt/m-p/4273402#M169522</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2024-11-07T09:20:09Z</dc:date>
    </item>
  </channel>
</rss>

