Kater SQL Functions Field declarations
MEASURE
Declares a measure: an aggregate that Kater works out again at each reader's grouping.
Family: Field declarations
A measure can be one aggregate, or a formula of other measures.
Syntax
MEASURE('name', expression [, NOT_ADDITIVE_ACROSS(dimension, ...)]) AS "Label"Arguments
| Argument | Description |
|---|---|
name | The field’s name, in quotes. No other field in this SELECT, or in the models it reads, can have it, in any letter case. |
expression | An aggregate, such as KATER__SUM(orders.amount), or a formula of measures, each written with EVAL. |
NOT_ADDITIVE_ACROSS(...) | Optional. The dimensions the measure cannot be added up across. See NOT_ADDITIVE_ACROSS. |
Returns
A measure. A reader that groups by other dimensions gets it worked out again at their grouping.
Usage notes
- Write it only in the model’s final SELECT, as a whole column.
- A formula of measures is worked out again from each measure. Units per order is the units divided by the orders of each group, not an average of the rows’ ratios.
- A window is never a measure. Declare it with
CUSTOM_CALCULATION. - To use the same measure twice in one SELECT, such as once as it is and once with
CLEAR(), declare the second one with its own name.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.channel AS "Channel", MEASURE('units_per_order', EVAL(orders.sum__quantity) / EVAL(orders.count_distinct__order_id)) AS "Units per Order"FROM kater_dataset.orders AS ordersGROUP BY orders.channelORDER BY 1| Channel | Units per Order |
|---|---|
| 3.06 | |
| paid | 3.01 |
| store | 3.09 |
| web | 3.04 |
See also
- Fields
- Other functions in Field declarations:
DIMENSION,CUSTOM_CALCULATION,NOT_ADDITIVE_ACROSS,EXCEL