Skip to main content
On this page

Kater SQL Functions Totals

KATER__ROW_TOTAL

The value and the other fields added up on each row, as a spreadsheet's row total.

Family: Totals

Syntax

KATER__ROW_TOTAL(field, field [, ...])

Arguments

ArgumentDescription
fieldThe first number to add.
fieldsThe other numbers to add, each a field of the query. One or more fields.

Returns

A number in the unit of the first field. 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

  • It compiles to COALESCE(field, 0) + COALESCE(other, 0) + ..., so an empty value adds 0.
  • Over measures it is a formula of measures, so the total of the row total is the sum of the totals of its fields.
  • Declare it with MEASURE when every field is a measure, as MEASURE('row_total', ...) AS "Total", and with DIMENSION otherwise. A query has one row total.

Example

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

SELECT
orders.channel AS "Channel",
MEASURE('gift_units', KATER__SUM(CASE WHEN orders.is_gift THEN orders.quantity ELSE 0 END)) AS "Gift Units",
MEASURE('other_units', KATER__SUM(CASE WHEN orders.is_gift THEN 0 ELSE orders.quantity END)) AS "Other Units",
MEASURE('row_total', KATER__ROW_TOTAL(gift_units, other_units)) AS "Total"
FROM kater_dataset.orders AS orders
GROUP BY
orders.channel
ORDER BY
1
ChannelGift UnitsOther UnitsTotal
email1942,1892,383
paid1812,1112,292
store2102,1202,330
web1641,9852,149

Compiles to

The call compiles to the same SQL on DuckDB and on Snowflake.

COALESCE(gift_units, 0) + COALESCE(other_units, 0)

See also