<?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: Why use a return inside a sumx in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042776#M160338</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555461" data-lia-user-login="GuillaumePower" class="lia-mention lia-mention-user"&gt;GuillaumePower&lt;/a&gt;&amp;nbsp;I've pasted the formatted formula below. The entire code after the "," on line 5 is the final parameter for the SUMX function. Since VAR is used then it must have a matching RETURN statement.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales PQ =
IF (
    [ShowValueForDates],
    SUMX (
        VALUES ( 'Date'[Fiscal Year Quarter Number] ),
        VAR CurrentFiscalYearQuarterNumber = 'Date'[Fiscal Year Quarter Number]
        VAR DaysSelected =
            CALCULATETABLE (
                VALUES ( 'Date'[Day of Fiscal Quarter Number] ),
                REMOVEFILTERS (
                    'Date'[Working Day],
                    'Date'[Day of Week],
                    'Date'[Day of Week Number]
                ),
                'Date'[DateWithSales] = TRUE
            )
        RETURN
            CALCULATE (
                [Sales Amount],
                'Date'[Fiscal Year Quarter Number] = CurrentFiscalYearQuarterNumber - 1,
                DaysSelected,
                ALLEXCEPT ( 'Date', 'Date'[Working Day], 'Date'[Day of Week] )
            )
    )
)&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 15 Jul 2024 14:55:00 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2024-07-15T14:55:00Z</dc:date>
    <item>
      <title>Why use a return inside a sumx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042726#M160334</link>
      <description>&lt;P&gt;Hello, I've seen this pattern to create a measure and I don't understand how we can make a return before the end of the sumx ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;Sales PQ :=
IF (
[ShowValueForDates],
SUMX (
VALUES ( ‘Date’[Fiscal Year Quarter Number] ),
VAR CurrentFiscalYearQuarterNumber = ‘Date’[Fiscal Year Quarter Number]
VAR DaysSelected =
CALCULATETABLE (
VALUES ( ‘Date’[Day of Fiscal Quarter Number] ),
REMOVEFILTERS (
‘Date’[Working Day],
‘Date’[Day of Week],
‘Date’[Day of Week Number]
),
‘Date’[DateWithSales] = TRUE
)
RETURN
CALCULATE (
[Sales Amount],
‘Date’[Fiscal Year Quarter Number] = CurrentFiscalYearQuarterNumber - 1,
DaysSelected,
ALLEXCEPT ( ‘Date’, ‘Date’[Working Day], ‘Date’[Day of Week] )
)
)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 14:29:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042726#M160334</guid>
      <dc:creator>GuillaumePower</dc:creator>
      <dc:date>2024-07-15T14:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why use a return inside a sumx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042776#M160338</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555461" data-lia-user-login="GuillaumePower" class="lia-mention lia-mention-user"&gt;GuillaumePower&lt;/a&gt;&amp;nbsp;I've pasted the formatted formula below. The entire code after the "," on line 5 is the final parameter for the SUMX function. Since VAR is used then it must have a matching RETURN statement.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales PQ =
IF (
    [ShowValueForDates],
    SUMX (
        VALUES ( 'Date'[Fiscal Year Quarter Number] ),
        VAR CurrentFiscalYearQuarterNumber = 'Date'[Fiscal Year Quarter Number]
        VAR DaysSelected =
            CALCULATETABLE (
                VALUES ( 'Date'[Day of Fiscal Quarter Number] ),
                REMOVEFILTERS (
                    'Date'[Working Day],
                    'Date'[Day of Week],
                    'Date'[Day of Week Number]
                ),
                'Date'[DateWithSales] = TRUE
            )
        RETURN
            CALCULATE (
                [Sales Amount],
                'Date'[Fiscal Year Quarter Number] = CurrentFiscalYearQuarterNumber - 1,
                DaysSelected,
                ALLEXCEPT ( 'Date', 'Date'[Working Day], 'Date'[Day of Week] )
            )
    )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 15 Jul 2024 14:55:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042776#M160338</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2024-07-15T14:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why use a return inside a sumx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042786#M160339</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555461" data-lia-user-login="GuillaumePower" class="lia-mention lia-mention-user"&gt;GuillaumePower&lt;/a&gt;&amp;nbsp;The RETURN statement inside the SUMX function is evaluated for each unique value of ‘Date’[Fiscal Year Quarter Number].&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 14:58:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042786#M160339</guid>
      <dc:creator>bhanu_gautam</dc:creator>
      <dc:date>2024-07-15T14:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why use a return inside a sumx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042846#M160343</link>
      <description>&lt;P&gt;Why should not more use in this measure a&lt;/P&gt;&lt;P&gt;MyMeasure =&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;Var TheSum= Sumx(...)&lt;/P&gt;&lt;P class="lia-align-left lia-indent-padding-left-30px"&gt;Return&amp;nbsp; TheSum&lt;/P&gt;&lt;P class="lia-align-left"&gt;How is it possible in one single measure to send many times a value : one for each return, isn't' it ?&lt;/P&gt;&lt;P class="lia-align-left"&gt;More, we have to think too, to the context of the measure, it seems very tricky for me.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 15:31:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4042846#M160343</guid>
      <dc:creator>GuillaumePower</dc:creator>
      <dc:date>2024-07-15T15:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why use a return inside a sumx</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4043000#M160350</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="555461" data-lia-user-login="GuillaumePower" class="lia-mention lia-mention-user"&gt;GuillaumePower&lt;/a&gt;&amp;nbsp;I agree that the construction of the measure is odd and complex. However, without additional information regarding the model, the intended use case, etc. it's hard to know why it was constructed the way it was. It may be that there is a good reason for it or it may be that it could be done much more simply and efficiently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use nested VAR statements in a measure, for example, you could write this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sales PQ =
VAR __Result = 
IF (
    [ShowValueForDates],
    SUMX (
        VALUES ( 'Date'[Fiscal Year Quarter Number] ),
        VAR CurrentFiscalYearQuarterNumber = 'Date'[Fiscal Year Quarter Number]
        VAR DaysSelected =
            CALCULATETABLE (
                VALUES ( 'Date'[Day of Fiscal Quarter Number] ),
                REMOVEFILTERS (
                    'Date'[Working Day],
                    'Date'[Day of Week],
                    'Date'[Day of Week Number]
                ),
                'Date'[DateWithSales] = TRUE
            )
        RETURN
            CALCULATE (
                [Sales Amount],
                'Date'[Fiscal Year Quarter Number] = CurrentFiscalYearQuarterNumber - 1,
                DaysSelected,
                ALLEXCEPT ( 'Date', 'Date'[Working Day], 'Date'[Day of Week] )
            )
    )
)
RETURN
  __Result&lt;/LI-CODE&gt;
&lt;P&gt;There are simpler ways to get a previous quarter calculation, such as the following examples:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Internet Sales (PQ) = 
    CALCULATE([Internet Sales],
        FILTER(ALL('Dates'),
            'Dates'[Date] &amp;gt;= MIN('Dates'[Prior Quarter Date]) &amp;amp;&amp;amp; 
            'Dates'[Date] &amp;lt;= MAX('Dates'[Prior Quarter Date])))

TI PQ 2 = 
    CALCULATE(
        [Internet Sales],
        DATESBETWEEN('Dates'[Date], MIN('Dates'[Prior Quarter Date]), MAX('Dates'[Prior Quarter Date]))
    )



NC Intenet Sales (PQ) = 
    VAR __MinPYDate = MIN('Dates'[Prior Quarter Date])
    VAR __MaxPYDate = MAX('Dates'[Prior Quarter Date])
    VAR __PQCalendar = CALENDAR(__MinPYDate, __MaxPYDate)
    VAR __Table = 
        SUMMARIZE(
            ALL('FactInternetSales'),
            'FactInternetSales'[OrderDate],
            "__Sales", SUM('FactInternetSales'[SalesAmount]))
    VAR __Result = SUMX( FILTER( __Table, [OrderDate] IN __PQCalendar), [__Sales] )
RETURN
    __Result
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 18:13:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Why-use-a-return-inside-a-sumx/m-p/4043000#M160350</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2024-07-15T18:13:03Z</dc:date>
    </item>
  </channel>
</rss>

