<?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's the difference creating the filter as a variable or using inside of the filter ? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801606#M148637</link>
    <description>&lt;P&gt;Hey&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you may have got things the wrong way round in your post? When you use the measure you&amp;nbsp;&lt;STRONG&gt;won't&lt;/STRONG&gt; get a consistent value to compare against each row. When using a measure in another function an implicit CALCULATE is wrapped around the measure and context transition occurs changing that row context into a filter context. Here's an example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Using MAX directly as a function you will get the same value across every row (the max date in the table). This is because a row has no filter context in this scenario&lt;/LI&gt;&lt;LI&gt;Using [Max Date] measure you get a date that is equal to the max date in that rows filter context. This is because Power BI actually runs &lt;FONT color="#808080"&gt;&lt;EM&gt;CALCULATE&lt;/EM&gt;(&lt;/FONT&gt; [Max Date]&lt;FONT color="#808080"&gt; ) &lt;/FONT&gt;under the hood.&lt;/LI&gt;&lt;LI&gt;Finally for clarity if you run CALCULATE( MAX( date ) ) then you will get the same result as [Max Date]&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be seen below. I've used ADDCOLUMNS as an example as it is also an iterator like FILTER&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;When context transition occurs it changes each row into a filter context. Since my dates are unique the Max Date for each row is equal to the date in the row itself. It may be clearer to see in this example using a simple SUM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Because rows 1 and 2 are duplicates the context of that calculation is "Give me the sales when Product = A and Sales = 200" since 2 rows satisfy the condition you can see we get 400 as a total. If the sales were different and it wasn't a duplicate you would get a different result since&amp;nbsp;"Give me the sales when Product = A and Sales = 200" and&amp;nbsp;"Give me the sales when Product = A and Sales = 300" are different.&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;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="714759" data-lia-user-login="brickanalyst" class="lia-mention lia-mention-user"&gt;brickanalyst&lt;/a&gt;&amp;nbsp;this is just scratching the surface but when I started to understand context transition my DAX became so much more powerful. Funny I missed this was an interview question and one I've used in the past. Understanding this shows you have a deep knowledge of evaluation contexts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps to clarify,&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2024 08:06:38 GMT</pubDate>
    <dc:creator>kriscoupe</dc:creator>
    <dc:date>2024-04-01T08:06:38Z</dc:date>
    <item>
      <title>what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3800525#M148570</link>
      <description>&lt;P&gt;I have seen a question in one of the interviews below :&lt;BR /&gt;&lt;BR /&gt;Let's say we have a dax measure&lt;BR /&gt;&lt;BR /&gt;[Max Date]:= MAX(DatesTable[Date])&lt;BR /&gt;then I use it in the following below;&lt;/P&gt;&lt;P&gt;FILTER(ALL(DatesTable), DatesTable[Date] &amp;lt;= [Max Date])&lt;BR /&gt;&lt;BR /&gt;then, I wanted to try this below instead;&lt;/P&gt;&lt;P&gt;FILTER(ALL(DatesTable), DatesTable[Date] &amp;lt;= MAX(DatesTable[Date]))&lt;BR /&gt;&lt;BR /&gt;these two are not giving the same results, explain why these two are acting different?&lt;BR /&gt;&lt;BR /&gt;That is the question, please share with details including videos, doc links if its needed.&lt;BR /&gt;thank you !&lt;/P&gt;</description>
      <pubDate>Sat, 30 Mar 2024 19:56:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3800525#M148570</guid>
      <dc:creator>brickanalyst</dc:creator>
      <dc:date>2024-03-30T19:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3800544#M148571</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="714759" data-lia-user-login="brickanalyst" class="lia-mention lia-mention-user"&gt;brickanalyst&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah this is a tricky one. When using the [Max Date] measure in another measure an implicit CALCULATE is wrapped around the function. Since FILTER is an iterator context transition occurs turning each row in the DatesTable into a filter context.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would achieve the same results if you changed your second formula to read&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FILTER(ALL(DatesTable), DatesTable[Date] &amp;lt;= CALCULATE( MAX(DatesTable[Date]) ) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check out context transition and implicit CALCULATE around measures for more info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps,&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Sat, 30 Mar 2024 20:50:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3800544#M148571</guid>
      <dc:creator>kriscoupe</dc:creator>
      <dc:date>2024-03-30T20:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801074#M148611</link>
      <description>&lt;P&gt;My best guess is when it's defined as variable it's just one value right lets say 3/31/2024 today. and every row in the filter function this date is going to be filtered by 3/31/2024 however when we filter max date within the filter function on number 2 it filters row by row and it gives a different result.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm not sure this idea is correct, but also I'm curious when we should use #1 and when we need to use #2&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 00:56:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801074#M148611</guid>
      <dc:creator>brickanalyst</dc:creator>
      <dc:date>2024-04-01T00:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801343#M148620</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="714759" data-lia-user-login="brickanalyst" class="lia-mention lia-mention-user"&gt;brickanalyst&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="237305" data-lia-user-login="kriscoupe" class="lia-mention lia-mention-user"&gt;kriscoupe&lt;/a&gt;&amp;nbsp; for sharing, I have some more suggestions here that I hope will help you.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;1. for the use of measure in the filter function. When you use it in a function, Power BI calculates the entire , once, and then this value is always used as a comparison value for each row calculated by the function. You can think of the&lt;BR /&gt;Max Date as a constant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. For the case of using max directly in the filter function. It is calculated for each row in the context modified by the function itself, which may result in different maximum date values being calculated for different subsets of the data, depending on the context established at each step of the evaluation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. If you need a consistent value to compare against all rows in the table, you can use the value stored in the measure, which is useful for global comparisons. If you need the comparison criteria to be adjusted according to the context of each row or subset of rows, you can use max directly in This method can be used for more dynamic calculations, where the maximum value may vary according to other filters or conditions applied to the data. More information on context can be found at the link: &lt;A href="https://blog.rajanand.org/mastering-dax-context-understanding-row-filter-and-evaluation-context" target="_blank"&gt;Mastering DAX Context: Understanding Row, Filter, and Evaluation Context (rajanand.org)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your Current Period does not refer to this, please clarify in a follow-up reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Clara Gong&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 05:36:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801343#M148620</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-01T05:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801606#M148637</link>
      <description>&lt;P&gt;Hey&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you may have got things the wrong way round in your post? When you use the measure you&amp;nbsp;&lt;STRONG&gt;won't&lt;/STRONG&gt; get a consistent value to compare against each row. When using a measure in another function an implicit CALCULATE is wrapped around the measure and context transition occurs changing that row context into a filter context. Here's an example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Using MAX directly as a function you will get the same value across every row (the max date in the table). This is because a row has no filter context in this scenario&lt;/LI&gt;&lt;LI&gt;Using [Max Date] measure you get a date that is equal to the max date in that rows filter context. This is because Power BI actually runs &lt;FONT color="#808080"&gt;&lt;EM&gt;CALCULATE&lt;/EM&gt;(&lt;/FONT&gt; [Max Date]&lt;FONT color="#808080"&gt; ) &lt;/FONT&gt;under the hood.&lt;/LI&gt;&lt;LI&gt;Finally for clarity if you run CALCULATE( MAX( date ) ) then you will get the same result as [Max Date]&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This can be seen below. I've used ADDCOLUMNS as an example as it is also an iterator like FILTER&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;When context transition occurs it changes each row into a filter context. Since my dates are unique the Max Date for each row is equal to the date in the row itself. It may be clearer to see in this example using a simple SUM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Because rows 1 and 2 are duplicates the context of that calculation is "Give me the sales when Product = A and Sales = 200" since 2 rows satisfy the condition you can see we get 400 as a total. If the sales were different and it wasn't a duplicate you would get a different result since&amp;nbsp;"Give me the sales when Product = A and Sales = 200" and&amp;nbsp;"Give me the sales when Product = A and Sales = 300" are different.&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;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="714759" data-lia-user-login="brickanalyst" class="lia-mention lia-mention-user"&gt;brickanalyst&lt;/a&gt;&amp;nbsp;this is just scratching the surface but when I started to understand context transition my DAX became so much more powerful. Funny I missed this was an interview question and one I've used in the past. Understanding this shows you have a deep knowledge of evaluation contexts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps to clarify,&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 08:06:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801606#M148637</guid>
      <dc:creator>kriscoupe</dc:creator>
      <dc:date>2024-04-01T08:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801674#M148643</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="237305" data-lia-user-login="kriscoupe" class="lia-mention lia-mention-user"&gt;kriscoupe&lt;/a&gt;&amp;nbsp;, you are right. My thoughts are consistent with yours. I am sorry that some problems in my expression have caused you some misunderstandings.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For the first case, Max Date is outside the filter, so all in the filter has no effect on it. For the second case, max is inside the filter, so the range is the entire table.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;As shown in the figure below, measure returns the count of each row, while measure2 returns the count of the entire table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure =
COUNT('Table'[date])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Measure 2 =
COUNTAX(ALL('Table'),'Table'[date])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="714759" data-lia-user-login="brickanalyst" class="lia-mention lia-mention-user"&gt;brickanalyst&lt;/a&gt;&amp;nbsp;,&lt;SPAN&gt;Here is a link that I hope will help you understand the filter context.&lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/Understand-the-Filter-Context-and-How-to-Control-it/ba-p/2452011" target="_blank" rel="noopener"&gt;Understand the Filter Context and How to Control i... - Microsoft Fabric Community&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your Current Period does not refer to this, please clarify in a follow-up reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Clara Gong&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>Mon, 01 Apr 2024 08:44:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3801674#M148643</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-01T08:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: what's the difference creating the filter as a variable or using inside of the filter ?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3817179#M149288</link>
      <description>&lt;P&gt;Thank you so much, It makes sense with examples.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Apr 2024 23:00:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/what-s-the-difference-creating-the-filter-as-a-variable-or-using/m-p/3817179#M149288</guid>
      <dc:creator>brickanalyst</dc:creator>
      <dc:date>2024-04-07T23:00:47Z</dc:date>
    </item>
  </channel>
</rss>

