Daily DAX : Day 415 LASTDATE
Power BI DAX: LASTDATE() Function
Syntax
LASTDATE ( )
What It Does
LASTDATE() returns a single date (as a table with one row and one column) that represents the latest (most recent) date in the current filter context from the specified date column.
It is a table function that returns a one-column, one-row table containing the last date.
Note: LASTDATE() ignores blank dates and only considers actual valid dates.
It respects the current filter context (slicers, filters, rows in visuals, etc.).
Key Differences
| Function | Returns | Use When |
|---|---|---|
LASTDATE(DateColumn) |
Table (1x1) | You need the date value inside CALCULATE or other functions |
MAX(DateColumn) |
Scalar value | You just need the date as a value (simpler in many cases) |
In most modern scenarios, MAX(Date[Date]) is preferred over LASTDATE(Date[Date]) because it's simpler and returns a scalar directly.
Common Use Cases
- Sales as of the Last Date in Context
- Stock/Inventory Balance at the Latest Date
- Last Date with Sales (ignoring future/blank dates)
Sales on Last Date =
CALCULATE (
SUM ( Sales[Amount] ),
LASTDATE ( 'Date'[Date] )
)
Latest Inventory = CALCULATE (
SUM ( Inventory[Quantity] ),
LASTDATE ( 'Date'[Date] )
)Last Date with Sales = CALCULATE (
LASTDATE ( 'Date'[Date] ),
Sales[Amount] > 0
)Practical Example
Imagine your report has a slicer where user selects January to June 2025.
LASTDATE('Date'[Date]) will return June 30, 2025 in that context.
Measure: Total Sales on Last Selected Date =
VAR LastVisibleDate = LASTDATE ( 'Date'[Date] )
RETURN
CALCULATE (
SUM ( Sales[SalesAmount] ),
'Date'[Date] = LastVisibleDate
)
Recommendation
For most new reports, use MAX('Date'[Date]) instead of LASTDATE() — it's cleaner and returns a scalar value directly.
Use LASTDATE() only when you specifically need a table result (rare cases).
Comments
Post a Comment