Computed Measures

Computed measures derive new values from your aggregated measures — ratios, percentages, spreads, conditional flags. They are evaluated after aggregation, so "revenue per order" is one expression, not an extra query.

In the app you build a computed measure in a pill-based editor — see Measures → Computed measures. This page describes the expression language and how a computed measure is written in a query. In the examples, measure names such as Revenue stand for the measures an expression refers to.

Operators

Expressions support standard arithmetic with the usual precedence:

Operator Description
+ - Addition, subtraction
* / Multiplication, division
( ) Grouping
> < >= <= Comparison
= <> Equal / not equal

Multiplication and division bind tighter than addition and subtraction. Comparisons bind loosest of all, so Revenue + 1 > Orders means (Revenue + 1) > Orders. A comparison produces 1 when true and 0 when false — its purpose is to feed IF, AND, and OR.

Division by zero is empty, not 0. A rate with nothing underneath it — revenue per order where there were no orders — has no value, so its cell shows an em-dash (—) rather than a zero that would read as "we measured it and it was nothing". It behaves like any other empty value; to show a number instead, say which one: COALESCE(Revenue / Orders, 0).

Built-in functions

Function Arguments Description
ABS(x) 1 Absolute value
ROUND(x) 1 Round to nearest integer
FLOOR(x) 1 Round toward negative infinity
CEIL(x) 1 Round toward positive infinity
SIGNUM(x) 1 Sign: returns -1, 0, or 1
MIN(a, b, ...) 2+ Minimum of two or more values
MAX(a, b, ...) 2+ Maximum of two or more values
TOTAL(m) 1 The unsegmented (grand) total of a referenced measure
IF(cond, then, else) 3 then when cond is true, otherwise else
COALESCE(a, b, ...) 2+ The first value that is not empty
IFNULL(a, b) 2 b when a is empty, otherwise a
AND(a, b, ...) 2+ True only when every argument is true
OR(a, b, ...) 2+ True when any argument is true
NOT(a) 1 Reverses true and false

Function names are case-insensitive (abs, Abs, and ABS all work). Arguments can be any expression, including nested function calls.

Empty values

A measure can be empty — for example, a Sum over a segment where every row's value is missing. That is different from zero, and Engeene keeps the difference, as SQL does. An all-empty result renders as an em-dash (—), never as a fake 0.

  • Arithmetic and the ordinary functions pass emptiness through: if any operand is empty, the result is empty.
  • Dividing by zero is empty too, whatever is being divided. The built-in Ratio and Coefficient Of Variation follow the same rule: a share of a total that is zero, and a spread measured against an average of zero, are empty.
  • A comparison against an empty value is unknown, not false. IF treats an unknown condition like a false one — it takes the else branch. This matches what a spreadsheet or a database does.
  • COALESCE and IFNULL are the only way to turn an empty value into a real one: IFNULL(Revenue, 0) reads "use Revenue, or 0 if it is empty".

So a ratio that shows 0 instead of nothing when there are no orders is COALESCE(Revenue / Orders, 0) — or, spelling out the condition, IF(Orders > 0, Revenue / Orders, 0).

An empty value sorts after every number in a Top or Bottom N, in both directions, and an alert on a measure that is empty does not fire — there is nothing to compare (Scheduled deliveries and alerts).

Example formulas

Expression Use case
Revenue / Orders Revenue per order
Signups / Visits * 100.0 Conversion rate as a percentage, one decimal (3.1)
Revenue / TOTAL(Revenue) Each segment's share of total revenue
ABS(Actual - Target) Absolute difference between two measures
ROUND(Revenue / Orders * 100) Rounded percentage
Revenue / Orders with no orders Empty (—): there is no "per order" to report
COALESCE(Revenue / Orders, 0) Average order value, 0 when there are no orders
IFNULL(Revenue, 0) Treat a missing total as zero
IF(AND(Revenue > 100, Orders < 10), 1, 0) Flag high-revenue, low-volume segments

Segmentation and filtering

Computed measures always operate on values in the same result row. When you segment by an attribute, the expression is evaluated independently per segment — never across segments (use TOTAL(...) to reach the grand total).

Country Sum(revenue) Count(orders) Revenue per Order
US 50 000 1 000 50.00
DE 12 000 400 30.00

Computed measures work with all query features: segmentation, global filters, per-measure filters on the base measures, and cross-dataset measures (the expression evaluates after joins are resolved).

Decimal precision

A computed measure is calculated exactly and rounded once, at the end, to a number of decimal places Engeene works out from the formula:

  • A measure keeps its property's decimals — money with two decimals stays at two. A Variance is the exception: it is in squared units, so it has twice its property's decimals (four for money), rounded to at most 9. A Standard Deviation keeps the property's decimals.
  • A number you type keeps the decimals you type. 100 has none, 100.0 has one, 100.00 has two.
  • Addition and subtraction use the higher precision of the two operands.
  • Multiplication uses the more precise side; division keeps the precision of the number being divided.
  • ABS, MIN, MAX, TOTAL, COALESCE, IFNULL preserve the most precise input; IF the more precise of its two branches.
  • FLOOR, CEIL, ROUND, SIGNUM and the boolean-valued functions produce integers.

So a rate of two whole-number counts needs a decimal in its formula. Clicks / Impressions * 100 has nothing but whole numbers in it and shows 3; Clicks / Impressions * 100.0 shows 3.1, and * 100.00 shows 3.10. Pair it with the Decimal format of the same precision and put the % sign in the label. A number in the divisor does not add decimals — Revenue / 2.5 keeps the precision of Revenue.

In a query

In a query, a computed measure is an entry in the metrics array with "type": "Computed", and measure references use positional $N notation — the zero-based position among the base (non-computed) measures in order of appearance:

{
  "metrics": [
    { "property": "orders.revenue", "aggregation": "Sum" },
    { "property": "orders.orderId", "aggregation": "Count" },
    { "type": "Computed", "expression": "$0 / $1", "label": "Revenue per Order" }
  ]
}

A Range or Coefficient Of Variation measure takes two base positions, so the $N of every base measure after it moves up by one more.

To use a measure that you do not want in the output, add it as a base measure anyway and ignore its column. TOTAL($N) references the unsegmented total of measure $N. Computed measures appear at their declared position in the response.

Ranking segments by a computed measure

A Top/Bottom N can rank by a computed measure instead of a base one. Spell it computedMetric — the position of the computed entry in the metrics array — in place of orderBy.metricIndex; the two are mutually exclusive, and computedMetric takes no aggregation:

{
  "metrics": [
    { "property": "orders.revenue", "aggregation": "Sum" },
    { "property": "orders.orderId", "aggregation": "Count" },
    { "type": "Computed", "expression": "$0 / $1", "label": "Revenue per Order" }
  ],
  "segmentBy": ["orders.country"],
  "orderBy": { "computedMetric": 2, "direction": "Descending" },
  "segmentLimit": 10,
  "includeOther": true
}

To rank by a computed measure you do not want in the output, add it as a trailing computed entry anyway — the response carries it, and a client simply renders the columns it asked to display.

includeOther behaves as it does everywhere else, and the residual row is worth being precise about: the "Other" row is the expression evaluated over the combined base totals of the segments outside the top N, not a fold of their individual computed values. For $0 / $1 that is the remaining countries' total revenue divided by their total orders — which is the only figure that is still a revenue-per-order number.

A computed ranking cannot be combined with sub-aggregations; such a request is refused with 400.

See the Query Endpoint for the full request format.

← Segmentation and Top-NList Endpoint →