Latest stock by product with LASTNONBLANKVALUE, plus a sold-out alert

Return the most recent stock count in one step with LASTNONBLANKVALUE, then flag products that are sold out or need reordering.

You will learn to

  • Return the last non-blank value of a measure with LASTNONBLANKVALUE
  • Turn a balance into a status label with SWITCH(TRUE())
  • Remember that a blank compares equal to zero

How it works

`LASTNONBLANKVALUE('Date'[Date], expression)` combines the two steps from the last recipe: it walks back through the visible dates and returns the **value** of the expression on the last date where it isn't blank. No outer `CALCULATE` needed: the …VALUE functions evaluate the expression with each date as a filter (an implicit `CALCULATE`), so a measure and a plain `SUM` give the same answer. LASTNONBLANK without VALUE has no such step, which is why it needs a measure or `CALCULATE` inside.

It is also the go-to pattern for "latest known value" questions beyond inventory: the latest exchange rate, the latest price, the latest headcount.

A balance becomes more useful as an **alert**. `SWITCH(TRUE(), …)` tests conditions in order and returns the first match, so put the most specific condition first: zero units is "Sold out" before "fewer than 15" can catch it. One caution: DAX treats a blank as equal to 0, so a product with no count at all would also read as sold out. Here every product is counted every month, so that can't happen.

Practice it hands-on with a real data model and a live report that updates as you type.

Latest Day Sales = LASTNONBLANKVALUE('Date'[Date], [Total Sales])