Skip to main content
On this page

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

ArgumentDescription
dimensionA 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 BY or one ACROSS, 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 orders
WHERE
KATER__IS_EQUAL_TO(orders.region, 'AMER')
GROUP BY
orders.region,
orders.channel
ORDER BY
2
RegionChannelUnitsRegion Units
AMERemail5462,179
AMERpaid6042,179
AMERstore5342,179
AMERweb4952,179

See also