Skip to main content
On this page

Kater SQL Functions Calculation context

RATIO

Divides one value by another on each row, such as units by orders.

Family: Calculation context

Syntax

RATIO(value, baseline)

Arguments

ArgumentDescription
valueThe number to divide: a measure or an expression.
baselineThe number to divide by: a measure or an expression.

Returns

The value divided by the baseline. It is null when the baseline is zero or a value is missing.

Usage notes

  • A measure in either argument is worked out at the row’s grouping, so the ratio is the ratio of the row’s totals.

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",
RATIO(orders.sum__quantity, orders.count_distinct__order_id) AS "Units per Order"
FROM kater_dataset.orders AS orders
GROUP BY
orders.channel
ORDER BY
1
ChannelUnitsOrdersUnits per Order
email2,3837783.06
paid2,2927623.01
store2,3307543.09
web2,1497063.04

See also