last(value: storable, [order_by(...)]?) -> value

last returns the value of its column from the last row in each aggregation group under the ordering that applies to that aggregation. In aggregate context you may supply an optional ordering argument to define last; otherwise the verb-level ordering applies, commonly ascending valid-from so that last is the newest row in the window. When used as an analytic function the call must be wrapped in window; the optional ordering argument is disallowed in that form and ordering must come from window. Nulls are ordinary values and can be chosen as the last value.

Domain

This is an aggregate function (aggregates rows over a group in aggregate verbs).

This is a window function (calculates over a group of multiple input rows using windowing).

Categories

Examples

aggregate last_val:last(metric_value, order_by(valid_from)), group_by(series)

Takes the metric_value from the last row in each series ordered by valid_from within the aggregate group.

make_col last_state:window(last(pod_phase), group_by(pod_uid), order_by(valid_from), frame(back:10m))

Computes the most recent pod_phase per pod over a ten-minute sliding window using last inside window.