Calculated Metrics
Calculated metrics let you create your own indicators based on existing metrics using mathematical formulas.
Formula syntax
A formula is written as a string using:
- Existing metric names in square brackets:
[clicks],[cost] - Arithmetic operators:
+,-,*,/ - Parentheses for grouping:
(,) - Functions:
ROUND(),ABS(),IF()
Formula examples
CPC: [cost] / [clicks]
CPL: [cost] / [leads]
ROAS: [revenue] / [cost] * 100
Profit: [revenue] - [cost]
Margin: ([revenue] - [cost]) / [revenue] * 100Configuration
A calculated metric is defined as an object in the calculated_metrics array:
json
{
"calculated_metrics": [
{
"name": "CPL",
"formula": "[cost] / [leads]",
"type": "money",
"description": "Cost per lead",
"format": "decimal_2"
}
]
}| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | A unique metric name |
formula | string | Yes | The mathematical formula |
type | string | No | Result type: float, money, percentage, integer |
description | string | No | Metric description for the interface |
format | string | No | Format: decimal_0, decimal_1, decimal_2, percent_1, percent_2 |
Available functions
| Function | Description | Example |
|---|---|---|
ROUND(value, decimals) | Rounding | ROUND([cpc], 2) |
ABS(value) | Absolute value | ABS([profit]) |
IF(condition, true_val, false_val) | Conditional expression | IF([clicks]>0, [cost]/[clicks], 0) |
Conditional logic
The IF function supports comparison operators: >, <, >=, <=, ==, !=:
json
{
"name": "CPC with division-by-zero protection",
"formula": "IF([clicks] > 0, [cost] / [clicks], 0)"
}Calculation order
- First, all standard metrics are pulled
- Then filters and groupings are applied
- Calculated metrics are computed last, based on the already-grouped data
- This means a calculated metric can't reference another calculated metric
Limitations
- A maximum of 10 calculated metrics per report
- A formula can't exceed 50 characters
- A formula can only reference metrics already added to the report
- Nested calculated metrics are not supported