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
| Argument | Description |
|---|---|
value | A 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
QUALIFYand 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__TOTALis 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 ordersGROUP BY orders.channelORDER BY 1| Channel | Units | All Units |
|---|---|---|
| 2,383 | 9,154 | |
| paid | 2,292 | 9,154 |
| store | 2,330 | 9,154 |
| web | 2,149 | 9,154 |