Skip to main content
On this page

Kater SQL Functions Field declarations

DIMENSION

Declares a dimension: a value on each row that a reader groups by and filters by.

Family: Field declarations

The first argument is the field’s name, and the AS alias is its label.

Syntax

DIMENSION('name', expression) AS "Label"

Arguments

ArgumentDescription
nameThe field’s name, in quotes. No other field in this SELECT, or in the models it reads, can have it, in any letter case.
expressionThe value for each row. It reads the row’s own values, such as orders.amount, and has no aggregate.

Returns

A dimension, with the type of its expression.

Usage notes

  • Write it only in the model’s final SELECT, as a whole column. It cannot go in a CTE, a subquery, a clause or one branch of a union.
  • The formula decides the kind. An aggregate is a measure, so DIMENSION around an aggregate gets a warning and a fix.
  • The label comes from AS. A field takes no @label comment.

Example

This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.

SELECT
DIMENSION('amount_band', CASE WHEN orders.amount >= 200 THEN 'Over 200' ELSE '200 or less' END) AS "Amount Band",
EVAL(orders.count_distinct__order_id) AS "Orders"
FROM kater_dataset.orders AS orders
GROUP BY
1
ORDER BY
1
Amount BandOrders
200 or less2,167
Over 200833

See also