DAX LASTDATE Function
Get last date in the current context in DAX.
In DAX (Data Analysis Expressions), LASTDATE
is a time intelligence function that returns the
last date in the current context for a column containing dates.
Syntax
LASTDATE(<dates>)
<dates>
: A column that contains date values.
Returns
- A single date value the latest date in the current context.
- Returns a blank if there are no dates in the context.
Example
- Basic usage
Assume you have a date column called Sales[OrderDate]
.
LastOrderDate := LASTDATE(Sales[OrderDate])
This returns the most recent OrderDate
based on the filter context (e.g., if you're slicing by year, month,
or customer).
- With
CALCULATE
You can use it to get a measure, like the total sales on the last order date:
SalesOnLastDate :=
CALCULATE(
SUM(Sales[Amount]),
LASTDATE(Sales[OrderDate])
)
LASTDATE vs MAX
LASTDATE()
and MAX()
might return the same value, but they behave differently in some time intelligence
scenarios, especially when working with filters and non-contiguous dates.
Function | Behavior |
---|---|
MAX(DateColumn) | Returns the latest date in the context even if the dates are not in a proper date table |
LASTDATE(DateColumn) | Assumes the column is from a valid date table and supports DAX time intelligence |
Common mistake
Using LASTDATE
without a proper date table can lead to unexpected results when doing advanced time intelligence (like YTD, MTD, etc.).