<?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: Arbitrary Shaped Sets in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271444#M55314</link>
    <description>&lt;P&gt;Hi Benjamin,&lt;/P&gt;&lt;P&gt;thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I know why Italians love DAX. It's about love and hate and it's a relatively stable relationship &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jan 2022 11:53:12 GMT</pubDate>
    <dc:creator>Strom</dc:creator>
    <dc:date>2022-01-07T11:53:12Z</dc:date>
    <item>
      <title>Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271145#M55293</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've been discussing evaluation contexts particularly with regard to arbitrary shaped sets with&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="345974" data-lia-user-login="Strom" class="lia-mention lia-mention-user"&gt;Strom&lt;/a&gt;&amp;nbsp;on this thread:&lt;/P&gt;&lt;P&gt;&lt;LI-MESSAGE title="Evaluation context - mixed filter and row context" uid="2240633" url="https://community.powerbi.com/t5/DAX-Commands-and-Tips/Evaluation-context-mixed-filter-and-row-context/m-p/2240633#U2240633" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original question has been marked as a solution but the conversation carried on and we've hit a an example which I can't explain so felt it best to open a new thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="345974" data-lia-user-login="Strom" class="lia-mention lia-mention-user"&gt;Strom&lt;/a&gt;&amp;nbsp;original file I've put this together, which I think demo's the issue:&amp;nbsp;&lt;A href="https://dobbsfamily-my.sharepoint.com/:u:/g/personal/ben_dobbs_me_uk/EcMenBlAA75GvLGSFJNwXHgBGHPUwn8x4Sr5QhA71FSR7g?e=wtb8Ft" target="_blank" rel="noopener"&gt;Demo File&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two measures:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sales Amount = 
    SUMX( 
        Sales, 
        Sales[Price]*Sales[Amount] 
    )

Sum Year = 
    SUMX( 
        VALUES( 'Calendar'[Year] ), 
        [Sales Amount] 
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Selecting a set like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;produces the following matrix:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would expect based on my understanding and a similar explanation in SQLBI's&amp;nbsp;&lt;A href="https://www.sqlbi.com/articles/keepfilters-a-new-dax-feature-to-correctly-compute-over-arbitrary-shaped-sets/" target="_blank" rel="noopener"&gt;Correctly Compute Over Arbitrary Shaped Sets&lt;/A&gt;&amp;nbsp;that Sum Year should be "wrong" but in a different way to the above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Starting from (2019, 11), (2019, 12), (2020, 1), (2020, 2), (2020, 3), my expectation would be that sub total for 2019 would be 8 because the year filter is removed leaving just (1, 2, 3, 11, 12) and then 2019 is put back.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What appears to be happening is that for the 2019 sub total we get an answer based on the following filter:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(2019, 11) = 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(2019, 12) = 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(2020, 11) = 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(2020, 12) = 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If anyone could help explain this it would be very much appreciated ( &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="71" data-lia-user-login="AlbertoFerrari" class="lia-mention lia-mention-user"&gt;AlbertoFerrari&lt;/a&gt;&amp;nbsp;, &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt;,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 08:27:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271145#M55293</guid>
      <dc:creator>bcdobbs</dc:creator>
      <dc:date>2022-01-07T08:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271444#M55314</link>
      <description>&lt;P&gt;Hi Benjamin,&lt;/P&gt;&lt;P&gt;thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I know why Italians love DAX. It's about love and hate and it's a relatively stable relationship &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 11:53:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271444#M55314</guid>
      <dc:creator>Strom</dc:creator>
      <dc:date>2022-01-07T11:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271915#M55350</link>
      <description>&lt;P&gt;The description we provide in the book applies to MDX queries and to other scenarios like those obtained using the context transition in a filter context managed by SUMMARIZE and/or ADDCOLUMNS.&lt;/P&gt;&lt;P&gt;Power BI uses a function (SUMMARIZECOLUMNS) that introduces another behavior (could it be called a bug on top of another bug?) which generates results that are less clear and predictable. We never described in detail what happened, because the important thing is that you should use KEEPFILTERS around the table function in the iterator. Or iterate over a single column.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 15:29:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2271915#M55350</guid>
      <dc:creator>marcorusso</dc:creator>
      <dc:date>2022-01-07T15:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272097#M55359</link>
      <description>&lt;P&gt;It definitely does seem buggy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you rewrite with CONCATENATEX instead of SUMX, then the Year subtotals are different but the Total matches:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using CONCATENATEX further as a debugger, we can see where Total comes from:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you think of a reason why SUMX and CONCATENATEX behave differently for the year subtotals?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;the important thing is that you should use KEEPFILTERS around the table function in the iterator. Or iterate over a single column.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Can you expand on this or link to something to read? Does VALUES ( 'Calendar'[Date] ) not count as a single column since it requires KEEPFILTERS in this case?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 16:54:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272097#M55359</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-01-07T16:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272301#M55365</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt; really appreciate you taking time to reply! I hadn't considered that it was an interaction with the SUMMARIZECOLUMNS from the matrix that was causing the issue! Realise the use of KEEPFILTERS or using a more descriptive single column to form the filter with is the way forward; this was more of an academic exercise in understanding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those interested I copied the DAX that the matrix forms and rewrote it using SUMMARISE/ADDCOLUMNS in DAX Studio connected to the demo file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;DEFINE

    VAR FilterTable =
        TREATAS (
            {
                ( 2019, 11 ),
                ( 2019, 12 ),
                ( 2020, 1 ),
                ( 2020, 2 ),
                ( 2020, 3 )
            },
            'Calendar'[Year],
            'Calendar'[Month]
        )
        
    VAR ResultTable =
        CALCULATETABLE (
            ADDCOLUMNS (
                SUMMARIZE (
                    Sales,
                    'Calendar'[Year]
                ),
                "Sum Year", 'Sales'[Sum Year]
            ),
            FilterTable
        )

EVALUATE

ResultTable&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This does indeed produce the expected "wrong" results:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I thought I'd made peace with this in my head until I saw&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;response below! (loving the use of COCATENATEX for debugging!)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 19:10:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272301#M55365</guid>
      <dc:creator>bcdobbs</dc:creator>
      <dc:date>2022-01-07T19:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272437#M55367</link>
      <description>&lt;P&gt;Thank you all (Benjamin, Marco, Alexis) for your time. The goal of my original question was not to find out how to get the right result. I know that. The goal was to understand how the evaluation of that query works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be great to find out more details about this behavior.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 20:12:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2272437#M55367</guid>
      <dc:creator>Strom</dc:creator>
      <dc:date>2022-01-07T20:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273362#M55379</link>
      <description>&lt;P&gt;It is probably because of the way SUM/SUMX is optimized for the subtotal, something that CONCATENATEX is not.&lt;/P&gt;&lt;P&gt;If you look at the storage engine queries, you should realize that there are two problems:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The way the storage engine requests are composed (which is consistent with the behavior expected with SUMMARIZE/ADDCOLUMNS)&lt;/LI&gt;&lt;LI&gt;The different behavior produced by the formula engine trying to "reuse" part of the data already computed to reduce the need for additional storage engine requests.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I didn't examine the CONCATENATEX query plan in detail, but I guess it does not have to generate SE queries for the intermediate totals.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure what you mean in the last question - can you elaborate?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Does VALUES ( 'Calendar'[Date] ) not count as a single column since it requires KEEPFILTERS in this case?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jan 2022 08:22:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273362#M55379</guid>
      <dc:creator>marcorusso</dc:creator>
      <dc:date>2022-01-08T08:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273372#M55381</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;is referring to the end of your first reply:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;SPAN&gt;We never described in detail what happened, because the important thing is that you should use KEEPFILTERS around the table function in the iterator. Or iterate over a single column."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In the Sum Year measure it is iterating over a single column.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I assumed you'd actually meant, apply the filter with a single column eg Month-Year to avoid the arbitrary shapes set all together.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jan 2022 08:50:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273372#M55381</guid>
      <dc:creator>bcdobbs</dc:creator>
      <dc:date>2022-01-08T08:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273610#M55389</link>
      <description>&lt;P&gt;Yes correct - by iterating over month, you are iterating over the wrong granularity (12 months even though you have 2 years selected). While it is the same for a SUM, it wouldn't be the same for MIN/MAX/AVG.&lt;/P&gt;&lt;P&gt;If you pay attention to that, you do not have to use KEEPFILTERS. Using KEEPFILTERS could be a good idea in general, but it wouldn't save you when you have a non-additive aggregation function.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jan 2022 14:18:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/2273610#M55389</guid>
      <dc:creator>marcorusso</dc:creator>
      <dc:date>2022-01-08T14:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Arbitrary Shaped Sets</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/3140672#M112130</link>
      <description>&lt;P&gt;Same here, I spent 3 days tryging to figure out what is happening on the subsume level but the logic for&amp;nbsp; totals does not match for subtotals.&lt;BR /&gt;As far as I understand&amp;nbsp; (which is different from your idea) is that the &lt;STRONG&gt;filter context for 2019 matrix row is 2019, 11 and 2019, 12&lt;/STRONG&gt; therefore&lt;U&gt; Values(year) should iterate only for 2019&lt;/U&gt; (as this is the only year from context coming from VALUES(year), isn't it? Why do you expect to have all months there as filter context&amp;nbsp; for this row is 11 and 12 only ?&lt;BR /&gt;Due to context transition (iteration over only 2019) - I would expect to 2019 become a new filter which should chenge the original one for this column (which is the same - 2019) -&amp;gt; therefore the subsume should be calculated in a correct way(2019, 11 and 2019 12).&amp;nbsp;&lt;BR /&gt;But the result for the 2019 subsume is year = 2019, 2020 and month = 11,12&lt;/P&gt;&lt;P&gt;(2019/11, 2019/12, 2020/11, 2020,12)&lt;/P&gt;</description>
      <pubDate>Sun, 19 Mar 2023 10:08:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Arbitrary-Shaped-Sets/m-p/3140672#M112130</guid>
      <dc:creator>Zx2000</dc:creator>
      <dc:date>2023-03-19T10:08:15Z</dc:date>
    </item>
  </channel>
</rss>

