<?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: Problem using variables in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776795#M3971</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variables in DAX are &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;immutable&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;once they are assigned a value at declaration. In your example,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;VAR vMax_Order_Gross_Sales_Amount =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;MAX ( tBrand[ORDER_TOTAL_AMOUNT] )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;the MAX() is evaluated before the SUMX and then the value obtained&amp;nbsp;stored in&amp;nbsp;&lt;SPAN&gt;vMax_Order_Gross_Sales_Amount.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;vMax_Order_Gross_Sales_Amount is used when the SUMX is iterating. &lt;STRONG&gt;Note that value is always the same.&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;THe measure, on the contrary, is calculated anew for each row as the SUMx iterates.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Aug 2019 12:19:59 GMT</pubDate>
    <dc:creator>AlB</dc:creator>
    <dc:date>2019-08-27T12:19:59Z</dc:date>
    <item>
      <title>Problem using variables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776732#M3968</link>
      <description>&lt;P&gt;I need to calculate the sum of all amounts for a column in a table avoiding duplicate IDs in another column in same table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At last I finished with two measures:&lt;/P&gt;&lt;P&gt;Max Order Gross Sales Amount =&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MAX(tBrand[ORDER_TOTAL_AMOUNT])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brand_Gross_Sales_Amount =&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUMX ( DISTINCT ( tBrand[ORDER_ID] ); [Max Order Gross Sales Amount] )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using these two different measures all is fine, but when I tried to use variables in same measure like this:&lt;/P&gt;&lt;P&gt;Brand_Gross_Sales_Amount =&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;VAR vMax_Order_Gross_Sales_Amount =&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MAX ( tBrand[ORDER_TOTAL_AMOUNT] )&lt;BR /&gt;RETURN&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUMX ( DISTINCT ( tBrand[ORDER_ID] ); vMax_Order_Gross_Sales_Amount )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In thi case returned amount is wrong (it is a lot bigger than first one). I have checked and I cannot find the problem. May you help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 11:16:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776732#M3968</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-27T11:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using variables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776795#M3971</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variables in DAX are &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;immutable&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;once they are assigned a value at declaration. In your example,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;VAR vMax_Order_Gross_Sales_Amount =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;MAX ( tBrand[ORDER_TOTAL_AMOUNT] )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;the MAX() is evaluated before the SUMX and then the value obtained&amp;nbsp;stored in&amp;nbsp;&lt;SPAN&gt;vMax_Order_Gross_Sales_Amount.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;vMax_Order_Gross_Sales_Amount is used when the SUMX is iterating. &lt;STRONG&gt;Note that value is always the same.&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;THe measure, on the contrary, is calculated anew for each row as the SUMx iterates.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 12:19:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776795#M3971</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2019-08-27T12:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using variables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776984#M3976</link>
      <description>&lt;P&gt;Thank you so much for your response. So, is possible to calculate sum for column values dependig on distinct ID values in other column in a more easy way? Do I need to use two different measures?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much again.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 15:23:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/776984#M3976</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-27T15:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using variables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/777079#M3981</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the way you've set it up is best. You could have it all in one measure by simply using the code of the first one on the second one (note you need the CALCULATE to trigger context transition):&lt;/P&gt;
&lt;PRE&gt;Brand_Gross_Sales_Amount =
SUMX (
    DISTINCT ( tBrand[ORDER_ID] );
    &lt;FONT color="#FF0000"&gt;CALCULATE ( MAX ( tBrand[ORDER_TOTAL_AMOUNT] ) )&lt;/FONT&gt;
)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; but having two measures as you had is more versatile and the best practice.&lt;/P&gt;
&lt;P&gt;Please mark as solved when we get to the solution so that others can see it too. If you find the posts useful please consider kudoing.&lt;/P&gt;
&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2019 17:17:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problem-using-variables/m-p/777079#M3981</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2019-08-27T17:17:06Z</dc:date>
    </item>
  </channel>
</rss>

