<?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: How does variable works with the Calculate Function? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-does-variable-works-with-the-Calculate-Function/m-p/3449517#M131358</link>
    <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="607092" data-lia-user-login="Jack007" class="lia-mention lia-mention-user"&gt;Jack007&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your second measure does not return the expected result because the revenue_calc value is calculated once, and never more. It is calculated when your variable is declared, when the calendar filter context is active. Your variable therefore stores revenues for the selected year. Then, in the "calculate()" part, this value is called directly and not recalculated, so the ALL() function doesn't change anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure my explanations are understandable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but you can find the idea in &lt;A href="https://www.sqlbi.com/articles/variables-in-dax/" target="_self"&gt;this article&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I answered your question, please mark my post as a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2023 10:22:52 GMT</pubDate>
    <dc:creator>Alf94</dc:creator>
    <dc:date>2023-09-27T10:22:52Z</dc:date>
    <item>
      <title>How does variable works with the Calculate Function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-does-variable-works-with-the-Calculate-Function/m-p/3449467#M131354</link>
      <description>&lt;P&gt;I am learning variables in BI.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a measure that calculates revenue for all years(remove filter context on calendar). I came up with 2 ways to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Method 1. Create a measure called Revenue,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;then I created a new measure called Total Revenue using the code below.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Total Revenue =&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var&lt;/SPAN&gt; &lt;SPAN&gt;aa&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;[Revenue]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;aa&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;This gives me the corrected result because revenue is same across years.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Method 2.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Total Revenue =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Var&lt;/SPAN&gt; &lt;SPAN&gt;revenue_calc&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Sales by store'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'Sales by store'&lt;/SPAN&gt;&lt;SPAN&gt;[quantity_sold]&lt;/SPAN&gt;&lt;SPAN&gt;*&lt;/SPAN&gt;&lt;SPAN&gt;'Sales by store'&lt;/SPAN&gt;&lt;SPAN&gt;[unit_price]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;revenue_calc&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;Total Revenue&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;I'm not getting the correct result because revenue varies from year to year.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Sep 2023 09:59:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-does-variable-works-with-the-Calculate-Function/m-p/3449467#M131354</guid>
      <dc:creator>Jack007</dc:creator>
      <dc:date>2023-09-27T09:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: How does variable works with the Calculate Function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-does-variable-works-with-the-Calculate-Function/m-p/3449517#M131358</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="607092" data-lia-user-login="Jack007" class="lia-mention lia-mention-user"&gt;Jack007&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your second measure does not return the expected result because the revenue_calc value is calculated once, and never more. It is calculated when your variable is declared, when the calendar filter context is active. Your variable therefore stores revenues for the selected year. Then, in the "calculate()" part, this value is called directly and not recalculated, so the ALL() function doesn't change anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure my explanations are understandable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; but you can find the idea in &lt;A href="https://www.sqlbi.com/articles/variables-in-dax/" target="_self"&gt;this article&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I answered your question, please mark my post as a solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 10:22:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-does-variable-works-with-the-Calculate-Function/m-p/3449517#M131358</guid>
      <dc:creator>Alf94</dc:creator>
      <dc:date>2023-09-27T10:22:52Z</dc:date>
    </item>
  </channel>
</rss>

