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
| Argument | Description |
|---|---|
field | The 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 addPARTITION BYto start again for each group. It writes its own frame, so itsOVERtakes noROWSorRANGE. - 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 ordersWHERE KATER__IS_ON_OR_AFTER(orders.order_date, DATE '2026-05-01')GROUP BY orders.order_monthORDER BY 1| Order Month | Units | Units Last Month |
|---|---|---|
| 2026-05-01 | 441 | 442 |
| 2026-06-01 | 403 | 442 |
| 2026-07-01 | 438 | 442 |
| 2026-08-01 | 454 | 442 |
| 2026-09-01 | 442 | 442 |
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)