<?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 Context transition for INDEX() function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4071596#M161633</link>
    <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I wrote the following code to have a table where I can see, for each customer the price plan code they had at the moment of their last transaction. The code seems to work well now. However, I do not understand why I need to add CALCULATETABLE() around Transactions table within the INDEX function. Without it, it seems that the INDEX gives back not the last transaction of the Customer, but the last transaction for all customers. In short, without CALCULATETABLE(), context transition does not work. Can anyone explain to me why is that? ADDCOLUMNS() supports context transition, and I already embedded MAX() function within a CALCULATE which should also make context transition work.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Why do i need to add CALCULATETABLE() around Transactions table?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;ADDCOLUMNS&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;VALUES&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions[Customer ID]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;"[@Price plan code]"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt; ( Transactions[Price plan code] ), &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;INDEX&lt;/SPAN&gt;&lt;SPAN&gt;(-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATETABLE&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions), &lt;/SPAN&gt;&lt;SPAN&gt;ORDERBY&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 31 Jul 2024 14:43:18 GMT</pubDate>
    <dc:creator>smoortema</dc:creator>
    <dc:date>2024-07-31T14:43:18Z</dc:date>
    <item>
      <title>Context transition for INDEX() function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4071596#M161633</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I wrote the following code to have a table where I can see, for each customer the price plan code they had at the moment of their last transaction. The code seems to work well now. However, I do not understand why I need to add CALCULATETABLE() around Transactions table within the INDEX function. Without it, it seems that the INDEX gives back not the last transaction of the Customer, but the last transaction for all customers. In short, without CALCULATETABLE(), context transition does not work. Can anyone explain to me why is that? ADDCOLUMNS() supports context transition, and I already embedded MAX() function within a CALCULATE which should also make context transition work.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Why do i need to add CALCULATETABLE() around Transactions table?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;ADDCOLUMNS&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;VALUES&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions[Customer ID]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;"[@Price plan code]"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt; ( Transactions[Price plan code] ), &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;INDEX&lt;/SPAN&gt;&lt;SPAN&gt;(-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATETABLE&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions), &lt;/SPAN&gt;&lt;SPAN&gt;ORDERBY&lt;/SPAN&gt;&lt;SPAN&gt;(Transactions[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 31 Jul 2024 14:43:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4071596#M161633</guid>
      <dc:creator>smoortema</dc:creator>
      <dc:date>2024-07-31T14:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Context transition for INDEX() function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4072161#M161668</link>
      <description>&lt;P&gt;The filter argument for CALCULATE (the INDEX(...) part in your case), is evaluated&amp;nbsp;&lt;EM&gt;before&lt;/EM&gt; the context transition happens.&amp;nbsp;In order for the Customer ID row context from ADDCOLUMNS to affect the Transactions table inside INDEX, you need to force a context transition to happen using CALCULATETABLE. (The outer CALCULATE does not suffice because Transactions is part of the filter argument, not the expression to be evaluated within that filter context.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this article for more detail on exactly this topic:&lt;A href="https://www.sqlbi.com/articles/context-transition-and-filters-in-calculate/" target="_blank"&gt;&amp;nbsp;Context Transition and Filters in CALCULATE - SQLBI&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 21:26:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4072161#M161668</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2024-07-31T21:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Context transition for INDEX() function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4072824#M161690</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Is there a simpler, more efficient way to achieve the same result? I use this table for a measure that calculates the number of active customers, sliced by the price plan they were in for their last transaction in the selected period.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 06:11:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4072824#M161690</guid>
      <dc:creator>smoortema</dc:creator>
      <dc:date>2024-08-01T06:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Context transition for INDEX() function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4073912#M161748</link>
      <description>&lt;P&gt;There are plenty of other ways to do this but I'm not sure what is the most efficient for your particular model.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another option to try:&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;FILTER (
    SUMMARIZE (
        Transactions,
        Transactions[Customer ID],
        Transactions[Price plan code],
        "@Date", MAX ( Transactions[Date] )
    ),
    CALCULATE (
        MAX ( Transactions[Date] ),
        ALL ( Transactions[Price plan code] )
    ) = [@Date]
)&lt;/LI-CODE&gt;
&lt;P&gt;This precalculatest the max date for each customer / code combination in your filter context and then filters it down to just the most recent code.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2024 15:08:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Context-transition-for-INDEX-function/m-p/4073912#M161748</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2024-08-01T15:08:32Z</dc:date>
    </item>
  </channel>
</rss>

