Skip to main content
On this page

Kater SQL Functions Windows

KATER__LAST_VALUE

The value on the last row of its partition, in the OVER's order.

Family: Windows

Syntax

KATER__LAST_VALUE(field) OVER ([PARTITION BY ...] ORDER BY ...)

Arguments

ArgumentDescription
fieldThe value it reads on each row: a field, or a measure, such as orders.sum__amount.

Returns

A value of the field’s own type. The field menu writes the @format of the field it reads beside it, or @format number(2) where that field has none and can have decimals.

Usage notes

  • Write OVER (ORDER BY ...), and add PARTITION BY to start again for each group. It writes its own frame, so its OVER takes no ROWS or RANGE.
  • It reads the whole partition, not only the rows up to this one, so each row gets the same last value.

Example

This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.

SELECT
orders.order_month AS "Order Month",
EVAL(orders.sum__quantity) AS "Units",
CUSTOM_CALCULATION(
'last_value__sum__quantity',
KATER__LAST_VALUE(orders.sum__quantity) OVER (ORDER BY orders.order_month)
) AS "Units Last Month"
FROM kater_dataset.orders AS orders
WHERE
KATER__IS_ON_OR_AFTER(orders.order_date, DATE '2026-05-01')
GROUP BY
orders.order_month
ORDER BY
1
Order MonthUnitsUnits Last Month
2026-05-01441442
2026-06-01403442
2026-07-01438442
2026-08-01454442
2026-09-01442442

Compiles to

LAST_VALUE(orders.sum__quantity) OVER (
ORDER BY orders.order_month
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
LAST_VALUE(orders.sum__quantity) OVER (ORDER BY orders.order_month)

See also