Stock at the last count: LASTNONBLANK vs. LASTDATE
When the last day in view has no inventory snapshot, LASTDATE returns blank; LASTNONBLANK finds the most recent date that has one.
You will learn to
- Explain why LASTDATE can return blank for snapshot data
- Find the last date that has data with LASTNONBLANK
- Use CALCULATE inside LASTNONBLANK to get context transition
How it works
`CALCULATE([Stock Units], LASTDATE('Date'[Date]))` evaluates stock on the **last visible day**. That works for months, quarters and years, which all end on a month end. But a report sliced by **weeks** ends on a Saturday, and on most Saturdays nobody counted stock, so the result is blank. `CLOSINGBALANCEMONTH` isn't right either: it jumps to the end of that month, a date after the selection.
What you want is "the most recent date **within the selection** that has a count". `LASTNONBLANK('Date'[Date], expression)` walks back through the visible dates, from last to first, and returns the first one where the expression isn't blank, as a one-date table you can use as a `CALCULATE` filter.
The expression must be evaluated **for each date**. Inside the iteration you are in a row context, so wrap an aggregation in `CALCULATE` (or use a measure) to turn that row into a filter. Without it, `COUNTROWS(Inventory)` counts the whole selection, is never blank, and the last date wins again.
Practice it hands-on with a real data model and a live report that updates as you type.
Last Sale Date = LASTNONBLANK('Date'[Date], CALCULATE(COUNTROWS(Sales)))