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

  1. Sales as of the Last Date in Context
  2. Sales on Last Date = 
    CALCULATE (
        SUM ( Sales[Amount] ),
        LASTDATE ( 'Date'[Date] )
    )
  3. Stock/Inventory Balance at the Latest Date
  4. Latest Inventory = CALCULATE (
        SUM ( Inventory[Quantity] ),
        LASTDATE ( 'Date'[Date] )
    )
  5. Last Date with Sales (ignoring future/blank dates)
  6. 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

Popular posts from this blog

Daily DAX : Day 131 SELECTEDMEASURE

Daily DAX : Day 446 INFO.CSDLMETADATA

Daily DAX : Day 453 ENDOFWEEK