<?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: SUM newest value by ID in selected timeframe and use last available value if blank in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4870927#M185699</link>
    <description>&lt;P&gt;thanks, that worked!&lt;/P&gt;</description>
    <pubDate>Mon, 10 Nov 2025 11:27:46 GMT</pubDate>
    <dc:creator>Phillegal</dc:creator>
    <dc:date>2025-11-10T11:27:46Z</dc:date>
    <item>
      <title>SUM newest value by ID in selected timeframe and use last available value if blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869187#M185634</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am currently struggling with one of my reports. My data source is a sharepoint list and I managed to make it work to get the version history, so every time someone makes a change to one sharepoint element I get a new row in my dataset.&amp;nbsp;&lt;BR /&gt;My colleagues not only want to see the newest data (I already made that work) but they also want to see what information was valid one or two month ago. The problem is that the data doesnt change in regular time intervals.&lt;BR /&gt;&lt;BR /&gt;So I am looking for a dax formula that returns the most recent date&amp;amp;time in a selected reporting timframe (selected Month X) for each item ID and then sums up the values. If there is no value for the selected timeframe it should use the last availbe entry for that ID.&lt;BR /&gt;&lt;BR /&gt;The dataset somewhat looks like this table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The slicer for the timeframe looks like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So if I select September 2025 I want to sum up "12" as the amount of available staff for ID 1 and "25" for ID 2 as there is no value for September for ID 2, so the result should be 37.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And if I select Oktober 2025 I want to make sure to take the newest entry for ID 2 as there can be multiple entrys for the same day and the value could be higher or lower, so the result should be 40.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Of course this is a very simplified version of my actual dataset. I really hope someone has an idea.&lt;BR /&gt;KR Philipp&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2025 14:04:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869187#M185634</guid>
      <dc:creator>Phillegal</dc:creator>
      <dc:date>2025-11-07T14:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: SUM newest value by ID in selected timeframe and use last available value if blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869246#M185636</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1286282" data-lia-user-login="Phillegal" class="lia-mention lia-mention-user"&gt;Phillegal&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Here is the DAX measure that should solve your problem:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Staff Selected Period = 
VAR SelectedDate = SELECTEDVALUE('Report Date'[Report date])
VAR SelectedMonthStart = EOMONTH(SelectedDate, -1) + 1  // First day of selected month
VAR SelectedMonthEnd = EOMONTH(SelectedDate, 0)         // Last day of selected month

// Get all IDs that exist in the dataset
VAR AllIDs = VALUES(YourTable[ID])

// For each ID find the most recent entry within or before the selected month
VAR LatestEntriesPerID =
    ADDCOLUMNS(
        AllIDs,
        "LatestValidDate", 
            CALCULATE(
                MAX(YourTable[Modified]),
                YourTable[Modified] &amp;lt;= SelectedMonthEnd,
                ALL(YourTable)
            )
    )

// For each ID with the latest date, get the most recent time and corresponding staff
VAR LatestStaffPerID =
    ADDCOLUMNS(
        LatestEntriesPerID,
        "LatestStaff",
            VAR CurrentID = [ID]
            VAR CurrentLatestDate = [LatestValidDate]
            RETURN
                CALCULATE(
                    MAX(YourTable[staff]),
                    FILTER(
                        YourTable,
                        YourTable[ID] = CurrentID &amp;amp;&amp;amp;
                        YourTable[Modified] = CurrentLatestDate &amp;amp;&amp;amp;
                        YourTable[Modified - time] = 
                            CALCULATE(
                                MAX(YourTable[Modified - time]),
                                YourTable[ID] = CurrentID,
                                YourTable[Modified] = CurrentLatestDate
                            )
                    )
                )
    )

RETURN
    SUMX(LatestStaffPerID, [LatestStaff])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Also you can use this approach:&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Staff Selected Period v2 = 
VAR SelectedDate = SELECTEDVALUE('Report Date'[Report date])
VAR SelectedMonthEnd = EOMONTH(SelectedDate, 0)

RETURN
SUMX(
    VALUES(YourTable[ID]),
    VAR CurrentID = [ID]
    VAR LatestDateInPeriod = 
        CALCULATE(
            MAX(YourTable[Modified]),
            YourTable[Modified] &amp;lt;= SelectedMonthEnd,
            ALLEXCEPT(YourTable, YourTable[ID])
        )
    VAR LatestTimeOnDate =
        CALCULATE(
            MAX(YourTable[Modified - time]),
            YourTable[Modified] = LatestDateInPeriod,
            ALLEXCEPT(YourTable, YourTable[ID])
        )
    RETURN
        CALCULATE(
            MAX(YourTable[staff]),
            YourTable[Modified] = LatestDateInPeriod,
            YourTable[Modified - time] = LatestTimeOnDate,
            ALLEXCEPT(YourTable, YourTable[ID])
        )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Uses &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;EOMONTH&lt;/FONT&gt; &lt;/STRONG&gt;to get the start and end of the &lt;U&gt;&lt;STRONG&gt;selected month&lt;/STRONG&gt;&lt;/U&gt;&lt;/LI&gt;&lt;LI&gt;For each ID finds the most recent entry on or before the end of the selected month&lt;/LI&gt;&lt;LI&gt;Also when multiple entries exist on the same day it takes the one with the latest time&lt;/LI&gt;&lt;LI&gt;If &lt;STRONG&gt;no entry&lt;/STRONG&gt; exists in the selected month it automatically uses the most recent &lt;STRONG&gt;previous entry&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;FONT size="5"&gt;Make Sure:&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;&lt;SPAN&gt;Your &lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;Report Date table&lt;/FONT&gt; &lt;/STRONG&gt;should have proper &lt;STRONG&gt;date values&lt;/STRONG&gt; (not just text)&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Your &lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;Modified&lt;/FONT&gt; &lt;/STRONG&gt;column should be a proper date type&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Your &lt;STRONG&gt;&lt;FONT color="#99CC00"&gt;Modified&lt;/FONT&gt; &lt;/STRONG&gt;- &lt;STRONG&gt;&lt;FONT color="#99CC00"&gt;time &lt;/FONT&gt;&lt;/STRONG&gt;column should be a proper time type&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;if this post helps, then I would appreciate a thumbs up&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;and&amp;nbsp;&lt;STRONG&gt;mark it as the solution&lt;/STRONG&gt;&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;to help the other members find it more quickly.&lt;/EM&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Nov 2025 14:49:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869246#M185636</guid>
      <dc:creator>Ahmed-Elfeel</dc:creator>
      <dc:date>2025-11-07T14:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: SUM newest value by ID in selected timeframe and use last available value if blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869405#M185642</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1286282" data-lia-user-login="Phillegal" class="lia-mention lia-mention-user"&gt;Phillegal&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try below measure:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Available Staff = 
VAR SelectedDate = SELECTEDVALUE('DateTable'[Date])
VAR SelectedYearMonth = YEAR(SelectedDate) * 100 + MONTH(SelectedDate)

RETURN
SUMX(
    VALUES('StaffTable'[ID]),
    VAR CurrentID = 'StaffTable'[ID]
    VAR LatestStaff = 
        CALCULATE(
            LASTNONBLANK('StaffTable'[staff], 1),
            FILTER(
                ALL('StaffTable'),
                'StaffTable'[ID] = CurrentID &amp;amp;&amp;amp;
                (YEAR('StaffTable'[Modified]) * 100 + MONTH('StaffTable'[Modified])) &amp;lt;= SelectedYearMonth
            ),
            LASTDATE('StaffTable'[Modified])
        )
    RETURN LatestStaff
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please give kudos or mark it as solution once confirmed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Praful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2025 18:02:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869405#M185642</guid>
      <dc:creator>Praful_Potphode</dc:creator>
      <dc:date>2025-11-07T18:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: SUM newest value by ID in selected timeframe and use last available value if blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869464#M185653</link>
      <description>&lt;P&gt;I'm assuming you have a separate Dates dimension being used in the slicer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use SUMX to iterate over IDs and INDEX to grab the latest staff # based on Modified DESC, Modified - time DESC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample data I used, copied from your snips.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;staffing&lt;/P&gt;
&lt;TABLE style="width: 500px;"&gt;
&lt;THEAD&gt;&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;version&lt;/TD&gt;
&lt;TD&gt;Modified&lt;/TD&gt;
&lt;TD&gt;Modified - time&lt;/TD&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;staff&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1.0&lt;/TD&gt;
&lt;TD&gt;8/31/2025&lt;/TD&gt;
&lt;TD&gt;0.08:00:50&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2.0&lt;/TD&gt;
&lt;TD&gt;9/5/2025&lt;/TD&gt;
&lt;TD&gt;0.10:00:00&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1.0&lt;/TD&gt;
&lt;TD&gt;8/31/2025&lt;/TD&gt;
&lt;TD&gt;0.11:20:00&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;25&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2.0&lt;/TD&gt;
&lt;TD&gt;10/8/2025&lt;/TD&gt;
&lt;TD&gt;0.08:30:40&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;31&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3.0&lt;/TD&gt;
&lt;TD&gt;10/8/2025&lt;/TD&gt;
&lt;TD&gt;0.09:00:00&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;31&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dates&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the measure I described at top.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Historical Staffing = 
VAR _maxDt = 
    CALCULATE( MAX( Dates[Date] ), ALLSELECTED( Dates ) )
RETURN
CALCULATE(
    SUMX(
        VALUES( staffing[ID] ),
        VAR _latestRow = 
            CALCULATETABLE( 
                INDEX( 
                    1, 
                    ORDERBY( staffing[Modified], DESC, staffing[Modified - time], DESC ), 
                    PARTITIONBY( staffing[ID] ) 
                ), 
                staffing[Modified] &amp;lt;= _maxDt 
            )
        RETURN
        CALCULATE( SUM( staffing[staff] ), _latestRow )
    ), 
    REMOVEFILTERS( Dates ) 
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: intellisense doesn't like INDEX without the relation arg, but it is valid as is (defaults to ALLSELECT of columns in ORDERBY And PARTITIONBY).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Snip of measure in action.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2025 20:38:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4869464#M185653</guid>
      <dc:creator>MarkLaf</dc:creator>
      <dc:date>2025-11-07T20:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: SUM newest value by ID in selected timeframe and use last available value if blank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4870927#M185699</link>
      <description>&lt;P&gt;thanks, that worked!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Nov 2025 11:27:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/SUM-newest-value-by-ID-in-selected-timeframe-and-use-last/m-p/4870927#M185699</guid>
      <dc:creator>Phillegal</dc:creator>
      <dc:date>2025-11-10T11:27:46Z</dc:date>
    </item>
  </channel>
</rss>

