Skip to content

LastNonEmpty

Time intelligenceSemi-additive

LastNonEmpty(expr, dateCol)

Semi-additive: per chart group, evaluates expr per date and returns the value at the latest date where it is non-empty — closing balances, latest inventory counts, current headcount. No additivity requirement on the operand (a Min or Avg balance is fine).

Composes under Calculate (a predicate picks the last non-empty date within that filter); DateShift cannot compose with a snapshot — it would fabricate a date that never happened. Charted on its own date axis, each bucket shows its period-end value automatically (the same behavior PeriodEndSnapshot gives you explicitly).

  • Stocks and levels, where summing over time is meaningless: inventory on hand, account balance, open pipeline, headcount.
  • Current readings on KPI cards — the latest count, whatever date it landed on.
ClosingStock := LastNonEmpty(Sum(Inventory.OnHand), Inventory.CountedAt)

Three small CTEs: value-per-date, the last date that has a value, and the pick:

// On a KPI card, filtered to one warehouse
ClosingStock := LastNonEmpty(Sum(Inventory.OnHand), Inventory.CountedAt)

On a grouped chart, both CTEs also carry the group keys — each region/warehouse picks its own last non-empty date.