Kater SQL Functions Calculation context
BY
Keeps only the grouping dimensions you name, in TOTAL, SHARE_OF_TOTAL or VALUE_FOR.
Family: Calculation context
BY() keeps none, so the value is the grand total.
Syntax
TOTAL(measure, BY(dimension, ...))Arguments
| Argument | Description |
|---|---|
dimension | A dimension that the query groups by. Give none, or one or more. |
Returns
Nothing of its own. It sets the grouping of the call that holds it.
Usage notes
- The query’s filters stay.
- Each dimension must be one that the query groups by.
- A call takes one
BYor oneACROSS, not both.
Example
This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.
SELECT orders.region AS "Region", orders.channel AS "Channel", EVAL(orders.sum__quantity) AS "Units", MEASURE('region_units', TOTAL(orders.sum__quantity, BY(orders.region))) AS "Region Units"FROM kater_dataset.orders AS ordersWHERE KATER__IS_EQUAL_TO(orders.region, 'AMER')GROUP BY orders.region, orders.channelORDER BY 2| Region | Channel | Units | Region Units |
|---|---|---|---|
| AMER | 546 | 2,179 | |
| AMER | paid | 604 | 2,179 |
| AMER | store | 534 | 2,179 |
| AMER | web | 495 | 2,179 |