Kater SQL Functions Totals
KATER__TOTAL
The total of the value over every row of the query, or over the rows of each group its PARTITION BY names.
Family: Totals
Syntax
KATER__TOTAL(field) OVER ([PARTITION BY ...])Arguments
| Argument | Description |
|---|---|
field | The number to total: a measure, a formula of measures, or another number of the query, such as google_ads_spend. |
Returns
A number in the unit of the value. 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 (PARTITION BY ...)to keep the fields each total is for, such as the currency, orOVER ()for the grand total. The fields are fields the query groups by. - It compiles to
TOTAL(field, BY(...)). A measure is worked out again over all the rows, so the total of a ratio is the ratio of the totals. Any other number is added up over the query’s rows, asSUM(field) OVER (PARTITION BY ...). - A measure that cannot be added up across a dimension, such as Revenue across Currency, keeps that dimension in
PARTITION BY, unless a filter holds the query to one value. So does a number made from one, such as a locked-in measure or a comparison. - A total counts every row that HAVING, QUALIFY and LIMIT would take out, so a query with a total has none of them.
- Declare it with
MEASUREwhen it totals a measure, such asMEASURE('total__google_ads_spend', ...), and withCUSTOM_CALCULATIONwhen it adds up the rows.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.currency AS "Currency", orders.channel AS "Channel", EVAL(orders.sum__amount) AS "Revenue", MEASURE( 'total__sum__amount', KATER__TOTAL(orders.sum__amount) OVER (PARTITION BY orders.currency) ) AS "Revenue (Total)" /* @format currency(currency, 2) */FROM kater_dataset.orders AS ordersWHERE KATER__IS_ONE_OF(orders.channel, 'email', 'paid', 'web')GROUP BY orders.currency, orders.channelORDER BY 1, 2| Currency | Channel | Revenue | Revenue (Total) |
|---|---|---|---|
| EUR | €22,431.55 | €63,226.16 | |
| EUR | paid | €20,213.32 | €63,226.16 |
| EUR | web | €20,581.29 | €63,226.16 |
| USD | $100,397.00 | $275,507.75 | |
| USD | paid | $94,166.76 | $275,507.75 |
| USD | web | $80,943.99 | $275,507.75 |
See also
- Charts
- Other functions in Totals:
KATER__ROW_TOTAL