Skip to main content
On this page

Kater SQL Functions Calculation context

TOTAL

Works a measure out at a broader grouping, such as all channels, on each row.

Family: Calculation context

Name the grouping with BY or ACROSS.

Syntax

TOTAL(value, BY(dimension, ...) | ACROSS(dimension, ...) [, SET(...)] [, IGNORE_FILTERS(...)])

Arguments

ArgumentDescription
valueA measure, a formula of measures, or any other number of the query.
BY(...) or ACROSS(...)The grouping of the total. BY keeps only the dimensions it names, and BY() keeps none. ACROSS removes the dimensions it names.
SET(...), IGNORE_FILTERS(...)Optional. More changes to the context: a dimension set to one value, or the query’s filters on a dimension removed.

Returns

The total on each row of the result.

Usage notes

  • A measure is worked out again at the broader grouping. A ratio’s total is the ratio of the totals, and a distinct count is counted again. Kater does not add up the rows shown.
  • Any other number, such as a dimension or a measure already in a changed context, is added up over the query’s rows, as a spreadsheet’s column total is.
  • The query’s filters stay. The total counts the rows before QUALIFY and the row limit.
  • A total of a measure has the measure’s name. When the query also shows the measure, declare the total with its own name, as the example does.
  • KATER__TOTAL is the table’s Total row, which adds up a column over every row of the query.

Example

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

SELECT
orders.channel AS "Channel",
EVAL(orders.sum__quantity) AS "Units",
MEASURE('all_units', TOTAL(orders.sum__quantity, BY())) AS "All Units"
FROM kater_dataset.orders AS orders
GROUP BY
orders.channel
ORDER BY
1
ChannelUnitsAll Units
email2,3839,154
paid2,2929,154
store2,3309,154
web2,1499,154

See also