Kater SQL Functions Field declarations
EXCEL
Writes a field's whole value as an Excel formula over the columns of the query's result.
Family: Field declarations
The compiler turns the formula into your warehouse’s SQL each time the query compiles.
Syntax
CUSTOM_CALCULATION('name', EXCEL('=formula')) AS "Label"Arguments
| Argument | Description |
|---|---|
'=formula' | The formula, in quotes, starting with =. It names columns by their field names, such as [@sum__quantity]. A quote inside the formula is written twice, and text inside it goes in double quotes. |
Returns
The formula’s value for each row of the result.
Usage notes
- Write it in a query or in the Sandbox, inside
CUSTOM_CALCULATION. It is the field’s whole value, never part of a larger expression. Shared models have no formulas. - A formula reads only the columns of its own query. Add a field to the query before a formula reads it.
[@revenue]reads this row, and[@revenue:-1]the row above.[revenue]reads every row, and[#total revenue]the measure worked out over every row at once.- The row above follows the query’s
ORDER BY. A formula that reads another row needs the query sorted. - The syntax is US Excel’s, with a comma between arguments. A value that Excel shows as an error, such as a division by zero, is empty.
- Lookups such as
VLOOKUPandXLOOKUPare not available. Bring the value into the query as a field.
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", EVAL(orders.count_distinct__order_id) AS "Orders", CUSTOM_CALCULATION('units_per_order', EXCEL('=ROUND([@sum__quantity]/[@count_distinct__order_id], 2)')) AS "Units per Order"FROM kater_dataset.orders AS ordersGROUP BY orders.channelORDER BY 1| Channel | Units | Orders | Units per Order |
|---|---|---|---|
| 2,383 | 778 | 3.06 | |
| paid | 2,292 | 762 | 3.01 |
| store | 2,330 | 754 | 3.09 |
| web | 2,149 | 706 | 3.04 |
See also
- Fields
- Other functions in Field declarations:
DIMENSION,MEASURE,CUSTOM_CALCULATION,NOT_ADDITIVE_ACROSS