Data Import & Export

Power BI DAX: Return the Latest Record Before a Selected Date

Camila MilosovichCamila Milosovich Nov 12, 2026 869 views

Question details

The user needs a DAX result that returns the most recent record for each Dataset Id whose CreatedOn date is on or before a selected date.

Power BI DAX: Return the Latest Record Before a Selected Date
Product
Microsoft Power BI DAX
Device & OS
not provided
Scenario
A Power BI model contains multiple records per Dataset Id and must identify the latest qualifying record based on a report-selected date.
Observed behavior
The required result must exclude records after the selected date and older qualifying records, while retaining the record with the greatest CreatedOn date for each dataset.
Before you start

Verify that CreatedOn is stored as a true Date or Date/Time column rather than text, and confirm that a marked date table is related to the model. Decide whether the result must respond to a slicer; measures are dynamic, while calculated tables are evaluated during model refresh.

Solution 1Recommended

Create a dynamic DAX measure for the latest record before the selected date

Use this approach when the result must change immediately as users select different dates in a report slicer.

A measure can use a virtual filtered table and TOPN to select the most recent qualifying row. The example below assumes the report visual provides one Dataset Id per row and DataId is a unique tie-breaker.

If CreatedOn is still text, create a date column first with DATEVALUE or change the column data type in Power Query. A measure returns a scalar value, not a standalone table of rows.

1
Create a real date column

In Power BI Desktop, open Modeling > New column and create a converted date column such as CreatedOnDate = DATEVALUE('Source'[CreatedOn]). If the text format is not recognized, use Home > Transform data and set the CreatedOn type to Date in Power Query.

2
Confirm the selected-date field

Create or use a calendar table, mark it as a date table through Table tools > Mark as date table, and place its Date column in the slicer. The measure can use SELECTEDVALUE('Date'[Date]) to read the current selection.

3
Create the dynamic measure

Open Modeling > New measure and enter: First Record Before Selected Date = VAR CutoffDate = SELECTEDVALUE('Date'[Date], MAX('Date'[Date])) VAR CurrentDataset = SELECTEDVALUE('Source'[Dataset Id]) VAR Candidates = FILTER(ALL('Source'), 'Source'[Dataset Id] = CurrentDataset && 'Source'[CreatedOnDate] <= CutoffDate) VAR LatestRow = TOPN(1, Candidates, 'Source'[CreatedOnDate], DESC, 'Source'[DataId], DESC) RETURN CONCATENATEX(LatestRow, 'Source'[DataId], ", ").

4
Add the measure to a dataset visual

Insert a table or matrix visual, add Source[Dataset Id] as the row field, and add the new measure as a value. Change the Date slicer to verify that the returned DataId changes and that records after the selected date are excluded.

Create a dynamic DAX measure for the latest record before the selected date
Calculated tables are not slicer-responsive: A calculated table is evaluated when the model refreshes, so SELECTEDVALUE in a calculated table does not update dynamically with a report slicer. Use the measure pattern for interactive results.
Free Microsoft Office alternative

Work with Imported Data and Date-Based Results in WPS Office

WPS Office does not execute Power BI DAX measures or interactive Power BI slicers, but it provides a free, lightweight way to inspect, filter, sort, and summarize exported Excel or CSV data. Its familiar spreadsheet interface supports migration from Microsoft Office files while keeping common formats compatible.

  1. 1. Open the exported dataset: In WPS Spreadsheet, select Menu > Open and choose the exported .xlsx or .csv file.
  2. 2. Convert and filter the date field: Select the CreatedOn column, use Data > Text to Columns or Format Cells to convert recognizable text into dates, then apply Data > Filter with a condition for dates on or before the cutoff.
  3. 3. Sort and review the latest row: Use Data > Sort to sort by Dataset Id and CreatedOn in descending order, then review the first qualifying record within each dataset.
Open and analyze exported Excel or CSV datasets with familiar spreadsheet tools.Filter records by CreatedOn and sort by Dataset Id and date to review the latest qualifying rows.Use pivot tables and formulas for lightweight summaries when a full Power BI model is not required.Maintain compatibility with Microsoft Excel XLSX and XLS files for a smoother migration.Use a free, lightweight office alternative for reviewing Power BI-exported data.
microsoft office alternative - wps office

Frequently Asked Questions

Can a Power BI calculated table respond to a date slicer?

No. Calculated tables are evaluated during data refresh rather than when a user changes a slicer. Use a measure with SELECTEDVALUE, FILTER, and TOPN for an interactive result.

How do I convert a text CreatedOn value into a DAX date?

Create a calculated column from Modeling > New column with DATEVALUE('Source'[CreatedOn]), or open Home > Transform data and change the column type to Date in Power Query.

How does TOPN choose one record when two rows have the same CreatedOn date?

Add a second descending sort expression, such as DataId, to TOPN. This provides a deterministic tie-breaker and ensures only one row is returned.

What should I use if no date is selected in the slicer?

Use a fallback in SELECTEDVALUE, such as MAX('Date'[Date]), or return BLANK when no single date is selected. The correct choice depends on whether the report should use the latest available date or require an explicit selection.

Can a DAX measure return a complete table of matching records?

No. A measure returns a scalar value. Use CONCATENATEX to display selected values as text, or create a calculated table or Power Query output when a physical table of rows is required.