<?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: When to use variables vs measures in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331663#M171965</link>
    <description>&lt;P&gt;Thank you. I understand conceptually what you mean, still trying to master it though.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2024 22:37:20 GMT</pubDate>
    <dc:creator>beanboy</dc:creator>
    <dc:date>2024-12-16T22:37:20Z</dc:date>
    <item>
      <title>When to use variables vs measures</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331627#M171962</link>
      <description>&lt;P&gt;Hi everyone, came across some DAX behavior I could use some clarification on. I have some pseudo-code below, but basically I am taking a unique Customers table and counting the rows that meet two conditions (based on the related Sales fact table).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What is stumping me is trying to aggregate this at a State level, for example. If I have the code use the VARIABLES in the return statement, it does not aggregate at a State level. It still outputs correctly in a table of Customers, but does not aggregate. However, if I instead copy each variable to a separate measure, and then switch the DAX to reference the MEASURES, the measure now correctly aggregates at a state level.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this for whatever reason is working as intented, so my question is&amp;nbsp;&lt;EM&gt;why&lt;/EM&gt; does it behave this way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, while I'm here, is my syntax for COUNTROWS using a FILTER statement correct, or could it be done more efficiently?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#NewCustomers = 

VAR __PriorMonthStart = EOMONTH ( TODAY(), -2 ) +1



VAR __VARIABLENumSalesAllPrior = 
    CALCULATE (
        [NumSales],
        'SalesData'[DateReceived] &amp;lt; __PriorMonthStart
    )


VAR __VARIABLENumSalesMonthPrior = 
    CALCULATE ( 
        [NumSales],
        DATESINPERIOD (
            'Calendar'[Date],
            __PriorMonthStart,
            1,
            MONTH
        )
    )




RETURN 
    CALCULATE ( 
        COUNTROWS ( 'Customers(unique)' ),
        FILTER (
            'Customers(unique)',
            AND (
                [MEASURENumSalesAllPrior] = 0,
                [MEASURENumSalesMonthPrior] &amp;gt; 0
            )
        )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 22:12:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331627#M171962</guid>
      <dc:creator>beanboy</dc:creator>
      <dc:date>2024-12-16T22:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: When to use variables vs measures</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331656#M171964</link>
      <description>&lt;P&gt;Measures are dynamic, they recalculate for each different filter context.&amp;nbsp; You may not always want that, so you materialize intermediate results into variables (which is actually a misnomer as for all intents and purposes these are constants, not variables)&amp;nbsp; so the values are no longer impacted by subsequent measure calculations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can materialize intermediate steps into scalar or table variables but the final result of the measure always must be a scalar value.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 22:31:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331656#M171964</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-12-16T22:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: When to use variables vs measures</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331663#M171965</link>
      <description>&lt;P&gt;Thank you. I understand conceptually what you mean, still trying to master it though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 22:37:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/When-to-use-variables-vs-measures/m-p/4331663#M171965</guid>
      <dc:creator>beanboy</dc:creator>
      <dc:date>2024-12-16T22:37:20Z</dc:date>
    </item>
  </channel>
</rss>

