Skip to main content
On this page

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

ArgumentDescription
fieldThe 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, or OVER () 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, as SUM(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 MEASURE when it totals a measure, such as MEASURE('total__google_ads_spend', ...), and with CUSTOM_CALCULATION when 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 orders
WHERE
KATER__IS_ONE_OF(orders.channel, 'email', 'paid', 'web')
GROUP BY
orders.currency,
orders.channel
ORDER BY
1,
2
CurrencyChannelRevenueRevenue (Total)
EURemail€22,431.55€63,226.16
EURpaid€20,213.32€63,226.16
EURweb€20,581.29€63,226.16
USDemail$100,397.00$275,507.75
USDpaid$94,166.76$275,507.75
USDweb$80,943.99$275,507.75

See also