<?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: Selecting the most recent row of data based on date selection in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2743342#M84396</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggestion. But I cannot see how I would add a filter based on date to this calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really want to be able to select a date and then get the calculation based on that selected date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Preferably the date selection is taking place from a different calendar table.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 11:07:02 GMT</pubDate>
    <dc:creator>MarDen94</dc:creator>
    <dc:date>2022-09-02T11:07:02Z</dc:date>
    <item>
      <title>Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2742533#M84341</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset is set up as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A table with status changes for tickets where each status change is one row of data with a unique ID, the tickets can be recognized by a caseID. See also below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal for me would be to select a value in the most recent row of data based on a dynamic (singular) date selection.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if the selected date would be 01-03-2022 then a value form first row of data would show for this specific CaseID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to to this with a MAXX statement:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Selected Status = 
    VAR SelectedCalendarDate = SELECTEDVALUE('Calendar'[CalendarDate])
    VAR SelectedCase = SELECTEDVALUE(Case_history[caseid])
    VAR SelectedHistoryDate = 
        MAXX(
            FILTER( ALL(Case_history),
                Case_history[createddate] &amp;lt; SelectedCalendarDate &amp;amp;&amp;amp; Case_history[caseid] = SelectedCase ),
                Case_history[createddate])
    VAR SelectedStatus = 
        MAXX(
            FILTER( ALL(Case_history),
                Case_history[createddate] = SelectedHistoryDate &amp;amp;&amp;amp; Case_history[caseid] = SelectedCase),
                Case_history[newvalue])
    RETURN SelectedStatus        &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The thing is when aggregating this data for a larger number of tickets the data takes very long to load.&lt;/P&gt;&lt;P&gt;Are there things that I can do to speed things up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NB. A way of calcaulting where the result is only aggregated data is also acceptable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 07:02:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2742533#M84341</guid>
      <dc:creator>MarDen94</dc:creator>
      <dc:date>2022-09-02T07:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2742738#M84351</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="436257" data-lia-user-login="MarDen94" class="lia-mention lia-mention-user"&gt;MarDen94&lt;/a&gt; , Refer if my blog on a similar topic can help &lt;/P&gt;
&lt;P&gt;&lt;A href="https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0" target="_blank"&gt;https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee884e" target="_blank"&gt;https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee884e&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 08:06:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2742738#M84351</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-09-02T08:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2743342#M84396</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggestion. But I cannot see how I would add a filter based on date to this calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really want to be able to select a date and then get the calculation based on that selected date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Preferably the date selection is taking place from a different calendar table.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 11:07:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2743342#M84396</guid>
      <dc:creator>MarDen94</dc:creator>
      <dc:date>2022-09-02T11:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2744734#M84508</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="436257" data-lia-user-login="MarDen94" class="lia-mention lia-mention-user"&gt;MarDen94&lt;/a&gt;&amp;nbsp;Hi Marden94,&lt;/P&gt;&lt;P&gt;In your measure, there is a nested iterator "MAXX - FILTER(ALL()..." which requires lots of time and resources when data is big.&lt;/P&gt;&lt;P&gt;Try not to filter the whole table (FILTER(column1, column2..) or use other table functions- like CALCULATETABLE rather than FILTER.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For&amp;nbsp; your measure, by using calculate you can get the same value as below;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Status2 = &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;VAR SelectedCalendarDate = SELECTEDVALUE('Calendar'[date])&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;VAR SelectedCase = SELECTEDVALUE(Case_history[caseid])&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;VAR SelectedHistoryDate = &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CALCULATE(max(Case_history[createddate]),&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case_history[createddate] &amp;lt; SelectedCalendarDate &amp;amp;&amp;amp; Case_history[caseid] = SelectedCase )&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;VAR SelectedStatus =&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CALCULATE(MAX(Case_history[newvalue]),&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Case_history[createddate] = SelectedHistoryDate &amp;amp;&amp;amp; Case_history[caseid] = SelectedCase)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;RETURN SelectedStatus&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps you.&amp;nbsp;&lt;BR /&gt;- please mark this post as solution if this post helped. appretiate kudo.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 11:37:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2744734#M84508</guid>
      <dc:creator>colacan</dc:creator>
      <dc:date>2022-09-03T11:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2744741#M84510</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="436257" data-lia-user-login="MarDen94" class="lia-mention lia-mention-user"&gt;MarDen94&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Actually filtering ALL ( Table ) is not required but you're doing that twice.&lt;/P&gt;
&lt;P&gt;The filter context already contains the table of each CaseID and no need to filter&amp;nbsp;ALL ( Table ) for the current CaseID. Much more simple formula as follows&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Selected Status =
VAR SelectedCalendarDate =
    SELECTEDVALUE ( 'Calendar'[CalendarDate] )
VAR TableBefore =
    FILTER ( Case_history, Case_history[createddate] &amp;lt; SelectedCalendarDate )
VAR PreviousRecord =
    TOPN ( 1, TableBefore, Case_history[createddate] )
VAR SelectedStatus =
    MAXX ( PreviousRecord, Case_history[newvalue] )
RETURN
    SelectedStatus&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 03 Sep 2022 12:02:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2744741#M84510</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-03T12:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the most recent row of data based on date selection</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2747814#M84695</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;thanks for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using this it gives me the correct status on the selected date. But when I try to use the created 'status2' measure to count the number of cases in a specific status on a historical date it shows all the cases which had that status (eg. "New") before the selected date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would there be an easy way to add this calculation to the measure OR create a seprate measure to that end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 12:40:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Selecting-the-most-recent-row-of-data-based-on-date-selection/m-p/2747814#M84695</guid>
      <dc:creator>MarDen94</dc:creator>
      <dc:date>2022-09-05T12:40:37Z</dc:date>
    </item>
  </channel>
</rss>

