<?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: What is Difference in these 2 average calculations in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422827#M175579</link>
    <description>&lt;P&gt;Hello &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="936698" data-lia-user-login="Coolpearl" class="lia-mention lia-mention-user"&gt;Coolpearl&lt;/a&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":keycap_1:"&gt;1️⃣&lt;/span&gt; Using FILTER() inside CALCULATE()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Avg Sales = CALCULATE( AVERAGE(TableName[SaleAmount]), FILTER(TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 ) )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;FILTER(TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0) returns a filtered table where SaleAmount is not 0.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;CALCULATE() then applies this filtered table to the AVERAGE() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Since FILTER() creates a row context, it allows complex filtering, such as using additional conditions or calculations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":keycap_2:"&gt;2️⃣&lt;/span&gt; Passing Table and Condition Directly in CALCULATE()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Avg Sales = CALCULATE( AVERAGE(TableName[SaleAmount]), TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;CALCULATE( AVERAGE(TableName[SaleAmount]), TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 ) applies a direct filter condition (TableName[SaleAmount] &amp;lt;&amp;gt; 0).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;This is more efficient because CALCULATE() internally converts TableName[SaleAmount] &amp;lt;&amp;gt; 0 into a filter over TableName without needing FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;However, this direct filtering only works with simple column filters and does not support row context like FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;If you need complex row-by-row filtering (e.g., comparing different columns, calculating on the fly, etc.), you must use FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;If the condition is simple (like TableName[SaleAmount] &amp;lt;&amp;gt; 0), passing it directly is preferred&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;For your case, both return the same result because the condition is straightforward. However, using FILTER() is unnecessary overhead in this scenario. The second approach is more efficient and should be preferred unless you require row context for advanced filtering.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Best Regards,&lt;BR /&gt;Udit&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accepting it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;Appreciate your Kudo &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt; Let's Connect: &lt;A href="https://www.linkedin.com/in/quantumudit/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;LinkedIn&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://www.youtube.com/@quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;YouTube&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://medium.com/@quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;Medium&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://github.com/quantumudit/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;GitHub&lt;/STRONG&gt;&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":sparkles:"&gt;✨&lt;/span&gt; Visit My Linktree: &lt;A href="https://linktr.ee/quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;LinkTree&lt;/STRONG&gt;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG style="color: #033f38;"&gt;Proud to be a Super User&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 22 Feb 2025 02:42:03 GMT</pubDate>
    <dc:creator>quantumudit</dc:creator>
    <dc:date>2025-02-22T02:42:03Z</dc:date>
    <item>
      <title>What is Difference in these 2 average calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422628#M175572</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Avg Sales= CALCULATE( AVERAGE(TableName[SaleAmount]), FILTER(TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 ))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Vs&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Avg Sales= CALCULATE( AVERAGE(TableName[SaleAmount]),TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;giving me same results.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;what is difference in 2?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;basically I want avg of measure having non zero values , I don't want to consider rows with 0 as denominator count.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2025 19:52:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422628#M175572</guid>
      <dc:creator>Coolpearl</dc:creator>
      <dc:date>2025-02-21T19:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: What is Difference in these 2 average calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422826#M175578</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="936698" data-lia-user-login="Coolpearl" class="lia-mention lia-mention-user"&gt;Coolpearl&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before discussing the difference between the two measures, here is how I would recommend writing this measure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Avg Sales =
CALCULATE (
    AVERAGE ( TableName[SalesAmount] ),
    KEEPFILTERS ( TableName[SalesAmount] &amp;lt;&amp;gt; 0 )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This version of the measure applies the single-column filter &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;TableName[SalesAmount] &amp;lt;&amp;gt; 0&lt;/FONT&gt;&lt;/STRONG&gt;, intersected with any existing filters (due to &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;KEEPFILTERS&lt;/STRONG&gt;&lt;/FONT&gt;), then computes the average of SalesAmount.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG style="font-family: inherit;"&gt;Comment on expanded tables&lt;/STRONG&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Whenever a physical table (i.e. a model table) is referenced in a DAX expression, it is treated by the engine as the "expanded table", which includes the table referenced plus columns of all tables on the 1-side of relationships with that table. The tables on the 1-side are joined to the table on the many-side. You can imagine a table constructed by left-outer-joining &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;to all related dimension tables&amp;nbsp; on the 1-side of relationships with it (assuming a typical star schema).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Difference between the two original measures:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The two measures apply the same filtering logic in two different ways. I can't see any situation where they would return different results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. First measure&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first measure applies a single filter:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The physical table &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;TableName&lt;/FONT&gt;&lt;/STRONG&gt; (expanded table) evaluated in the existing filter context, then filtered row-by-row using the iterator &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;FILTER&lt;/STRONG&gt;&lt;/FONT&gt;, to include only those rows where &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName[SalesAmount] &amp;lt;&amp;gt; 0&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This measure may perform poorly because the expanded &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;table is materialized in memory and filtered row-by-row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2. Second measure&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The second measure applies two filters.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The physical table &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;(expanded table) evaluated in the existing filter context.&lt;/LI&gt;
&lt;LI&gt;The boolean condition&lt;BR /&gt;
&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;TableName[SalesAmount] &amp;lt;&amp;gt; 0&lt;BR /&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
which is translated into this:&lt;BR /&gt;
&lt;PRE&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;FILTER ( ALL ( TableName[SalesAmount] ), TableName[SalesAmount] &amp;lt;&amp;gt; 0 )&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
This is a single-column table containing all nonzero values of SalesAmount (ignoring filter context).&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;These two filters are applied simultaneously, so effectively "intersected". Since the set of all nonzero values of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;(from 2nd filter) is a superset of the values of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;in &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;in the existing filter context (from 1st filter), any rows of TableName where SalesAmount &amp;lt;&amp;gt; 0 are excluded, giving the same result as the first measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Potential unexpected results from both of these measures&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In both of the original measures, the calculation performed in the first argument of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;CALCULATE&lt;/STRONG&gt; &lt;/FONT&gt;is relatively simple:&lt;/P&gt;
&lt;PRE&gt;AVERAGE ( TableName[SalesAmount] )&lt;/PRE&gt;
&lt;P&gt;As a result, in "typical" situations, the fact that the expanded table is used within &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;CALCULATE&lt;/FONT&gt;&lt;/STRONG&gt;'s filter arguments will usually not result in any unexpected results. The measure returns the average of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;within the existing filter context, excluding any zero &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;values. Even if you have, say, a filter in your report on &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesValue&lt;/STRONG&gt; &lt;/FONT&gt;itself (such as &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesValue &amp;gt;= 100&lt;/STRONG&gt;&lt;/FONT&gt;), both measures would still return the expected average of nonzero values&amp;nbsp;&lt;EM&gt;within&lt;/EM&gt; that filter context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, there are situations where applying these kinds of filters could result in unexpected results:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;An existing "complex filter" involving columns both within and outside the expanded TablleName table.&lt;/STRONG&gt;&lt;BR /&gt;A &lt;A href="https://www.sqlbi.com/articles/keepfilters-a-new-dax-feature-to-correctly-compute-over-arbitrary-shaped-sets/" target="_blank" rel="noopener"&gt;complex filter (or arbitrarily-shaped set&lt;/A&gt;) is a filter consisting of multiple columns that is not an intersection of single-column filters. For example, &lt;STRONG&gt;"Red Products in 2017 &lt;EM&gt;or&lt;/EM&gt; Green Products in 2018"&lt;/STRONG&gt;. If you had such a filter involving say a column within the expanded &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;table and a column outside the expanded &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;table, either of the original measures could "break" the relation between the columns expressed in the complex filter (complex filter reduction). To be honest, this would have to be a pretty contrived situation. It &lt;EM&gt;could&lt;/EM&gt; come about if a table involved in the complex filter had many-to-many relationships with Sales (since tables related by many-to-many relationships are not included in expanded tables).&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Performing a more complex calculation involving multiple columns, for example sales per day.&lt;BR /&gt;&lt;/STRONG&gt;Take this measure for example:&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;
&lt;PRE&gt;Sales per Day =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;    DIVIDE (&lt;BR /&gt;        SUM ( TableName[SalesAmount] ),&lt;BR /&gt;        COUNTROWS ( 'Date' )&lt;BR /&gt;    ),&lt;BR /&gt;    FILTER ( TableName, TableName[SalesAmount] &amp;lt;&amp;gt; 0 )&lt;BR /&gt;)&lt;/PRE&gt;
Assuming &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;'Date'&lt;/STRONG&gt;&lt;/FONT&gt; is on the 1-side of a 1-to-many relationship with &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt;&lt;/FONT&gt;, the 2nd argument of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;CALCULATE&lt;/STRONG&gt; &lt;/FONT&gt;would limit the visible rows of 'Date' to just those related to rows of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt; &lt;/FONT&gt;where &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount &amp;lt;&amp;gt; 0.&lt;/STRONG&gt;&lt;/FONT&gt; If you have filtered 'Date' to a 7-day period and nonzero &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;values occurred only on 3 of those days, &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;COUNTROWS ( 'Date' )&lt;/FONT&gt;&lt;/STRONG&gt; would return 3 rather than 7.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;STRONG&gt;Conclusions:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The two original measures apply the same filtering logic, and should return the same results in all scenarios.
&lt;OL&gt;
&lt;LI&gt;The first measure filters &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt;&amp;nbsp;(&lt;/FONT&gt;expanded table) row-by-row with the condition &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount &amp;lt;&amp;gt; 0&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;The second measure applies &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;TableName&lt;/STRONG&gt;&amp;nbsp;(expanded table)&amp;nbsp;&lt;/FONT&gt;as a filter, and simultaneously applies all nonzero values of &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;SalesAmount&lt;/STRONG&gt; &lt;/FONT&gt;as a filter. The combination of these gives the same filtering result as the first measure.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;However, as a general rule, it is best to filter columns, not tables, because of
&lt;OL&gt;
&lt;LI&gt;The unexpected consequences of filtering expanded tables.&lt;/LI&gt;
&lt;LI&gt;Better performance when filtering columns, since the expanded table need not be materialized.&lt;BR /&gt;See &lt;A href="https://www.sqlbi.com/articles/filter-columns-not-tables-in-dax/" target="_blank" rel="noopener"&gt;this article.&lt;/A&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;If you want to apply filters while retaining existing filters (i.e. intersected with existing filters), wrap the filter(s) within KEEPFILTERS.&lt;BR /&gt;This ensures that filters are robust to any existing complex filters that might have been applied.&lt;BR /&gt;See &lt;A href="https://www.sqlbi.com/articles/keepfilters-a-new-dax-feature-to-correctly-compute-over-arbitrary-shaped-sets/" target="_blank" rel="noopener"&gt;this article&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;You may see no difference between column vs table filters in "simple" situations, but I believe it is best to write measures that are robust and will return correct results in all situations (which can't always be anticipated in advance). The linked articles cover this in much more depth &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2025 02:45:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422826#M175578</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2025-02-22T02:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: What is Difference in these 2 average calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422827#M175579</link>
      <description>&lt;P&gt;Hello &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="936698" data-lia-user-login="Coolpearl" class="lia-mention lia-mention-user"&gt;Coolpearl&lt;/a&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":keycap_1:"&gt;1️⃣&lt;/span&gt; Using FILTER() inside CALCULATE()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Avg Sales = CALCULATE( AVERAGE(TableName[SaleAmount]), FILTER(TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 ) )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;FILTER(TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0) returns a filtered table where SaleAmount is not 0.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;CALCULATE() then applies this filtered table to the AVERAGE() function.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Since FILTER() creates a row context, it allows complex filtering, such as using additional conditions or calculations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":keycap_2:"&gt;2️⃣&lt;/span&gt; Passing Table and Condition Directly in CALCULATE()&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Avg Sales = CALCULATE( AVERAGE(TableName[SaleAmount]), TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;CALCULATE( AVERAGE(TableName[SaleAmount]), TableName, TableName[SaleAmount] &amp;lt;&amp;gt; 0 ) applies a direct filter condition (TableName[SaleAmount] &amp;lt;&amp;gt; 0).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;This is more efficient because CALCULATE() internally converts TableName[SaleAmount] &amp;lt;&amp;gt; 0 into a filter over TableName without needing FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;However, this direct filtering only works with simple column filters and does not support row context like FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;If you need complex row-by-row filtering (e.g., comparing different columns, calculating on the fly, etc.), you must use FILTER().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;If the condition is simple (like TableName[SaleAmount] &amp;lt;&amp;gt; 0), passing it directly is preferred&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;For your case, both return the same result because the condition is straightforward. However, using FILTER() is unnecessary overhead in this scenario. The second approach is more efficient and should be preferred unless you require row context for advanced filtering.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P dir="ltr"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;Best Regards,&lt;BR /&gt;Udit&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accepting it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;Appreciate your Kudo &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":rocket:"&gt;🚀&lt;/span&gt; Let's Connect: &lt;A href="https://www.linkedin.com/in/quantumudit/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;LinkedIn&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://www.youtube.com/@quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;YouTube&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://medium.com/@quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;Medium&lt;/STRONG&gt;&lt;/A&gt; || &lt;A href="https://github.com/quantumudit/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;GitHub&lt;/STRONG&gt;&lt;/A&gt;&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":sparkles:"&gt;✨&lt;/span&gt; Visit My Linktree: &lt;A href="https://linktr.ee/quantumudit" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;LinkTree&lt;/STRONG&gt;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG style="color: #033f38;"&gt;Proud to be a Super User&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2025 02:42:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4422827#M175579</guid>
      <dc:creator>quantumudit</dc:creator>
      <dc:date>2025-02-22T02:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: What is Difference in these 2 average calculations</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4593438#M175907</link>
      <description>&lt;P&gt;thank you audit and Owen for detail response. Very much helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 17:42:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-Difference-in-these-2-average-calculations/m-p/4593438#M175907</guid>
      <dc:creator>Coolpearl</dc:creator>
      <dc:date>2025-03-03T17:42:41Z</dc:date>
    </item>
  </channel>
</rss>

