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
| Argument | Description |
|---|---|
field | The first number to add. |
fields | The 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
MEASUREwhen every field is a measure, asMEASURE('row_total', ...) AS "Total", and withDIMENSIONotherwise. 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 ordersGROUP BY orders.channelORDER BY 1| Channel | Gift Units | Other Units | Total |
|---|---|---|---|
| 194 | 2,189 | 2,383 | |
| paid | 181 | 2,111 | 2,292 |
| store | 210 | 2,120 | 2,330 |
| web | 164 | 1,985 | 2,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
- Charts
- Other functions in Totals:
KATER__TOTAL