Metrics
Detects abnormal values of an aggregate of a field, such as its sum or average.
The Metrics monitor computes a number from the values of a field, such as their sum, average, or number of distinct values, and alerts you when this number is unusual.
When to Use
- Business metrics: Track a daily business metric, such as the sum of an amount field, and get alerted when it drops unexpectedly.
- Stable indicators: The daily sum of an amount field varies a lot with the number of rows, but its average is more predictable. Monitor the average to detect pricing or tracking issues.
- Diversity of values: Track the number of distinct values of a field each day, such as the number of distinct customer IDs.
- Custom formulas: Monitor a ratio with a custom aggregation, for example the share of the amounts that match a condition.
To monitor a metric computed by a SQL query of your own, use Custom Metrics. To check individual values against a range, use Value Range.
How It Works
Each data point is the aggregation of the field over the rows of a period (in incremental scan mode) or over the whole table (in full dataset scan mode). The following aggregations are available:
| Aggregation | Computes |
|---|---|
| Sum | The sum of the values. |
| Average | The mean of the values. |
| Distinct count (default) | The number of distinct values. Accepts fields of any type. |
| Min | The smallest value. |
| Max | The largest value. |
| Variance | The variance of the values. |
| Standard Deviation | The standard deviation of the values. |
| Quantile | The value below which a given share of the values falls. Set the Quantile value between 0 and 1 (for example, 0.5 for the median). |
| Normalized Average | The average of the values rescaled between 0 and 1, using the minimum and maximum of the field over all the scanned data. Use it to compare trends across sources with different scales, or to monitor a trend without exposing the actual values. |
| Custom Aggregation | An aggregate SQL expression of your own (see Custom Aggregation). |
The monitor fails when a data point is outside the threshold:
- Dynamic (default): Outside the confidence band that a machine learning (ML) model predicts from the history of the metric, including its seasonality.
- Static: Outside the minimum and maximum you set. For example, the daily revenue can never be negative.
- Relative: The change compared to the previous data point, as a value or a percentage, is outside the range you set.
Custom Aggregation
A custom aggregation is a SQL expression that returns a single numeric value per data point. Use it for an aggregate function that is not in the list, or to combine several functions. For example:
MEDIAN(datasetId:my_field)
SUM(CASE WHEN datasetId:my_status_field = 'my_value' THEN datasetId:my_field ELSE 0 END) / SUM(datasetId:my_field)In the expression, fields use a special format, datasetId:fieldName. In the UI, start typing the name of a field and select it in the autocompletion list to insert it in this format.
The expression can only use the fields of the monitored dataset (and of the datasets joined to it). It cannot contain SELECT or query other tables.
Example
You want to know when the average order value is unusual. Create a Metrics monitor on orders with the following settings:
- Column to monitor:
order_total. - Metric type: Average.
- Monitoring mode: Incremental scan, with
created_atas the time window column and a daily time-based data aggregation. - Threshold: Dynamic (default).
The average order value is usually about 60. On June 12, a pricing bug applies a 90% discount to all products, and the average order value of the day drops to 8. The data point of June 12 is 8, far below the expected range, so the monitor fails.
Configure the Monitor
Metrics Settings
| Setting | Description | Default |
|---|---|---|
| Column to monitor | The field to aggregate. Not needed for a custom aggregation. | None |
| Metric type | The aggregation (see How It Works). | Distinct count |
| Quantile value | For Quantile only: a number between 0 and 1. | None |
Common Settings
- Threshold: Dynamic (default), static, or relative. See Thresholds.
- Scan mode: Incremental (default) or full dataset. See Scan Modes.
- Where clause and group by: See Where Clause, Group By, and Joins. For example, group by a country field to compute one average per country.
- Joins: Join other datasets to use their fields in a custom aggregation, where clause, or group by. See Joins.
Monitor as Code
The monitor kind is Metrics. The following YAML creates the monitor of the example:
kind: Metrics
field: order_total
aggregation:
kind: Average
timeWindow:
field: created_at
firstRun: P365D
frequency: P1D| Parameter | Required | Description |
|---|---|---|
field | Yes, except for CustomAggregation | The field to aggregate. |
aggregation.kind | Yes | Sum, Average, DistinctCount, Min, Max, Variance, StandardDeviation, Quantile, NormalizedAverage, or CustomAggregation. |
aggregation.quantile | For Quantile | A number between 0 and 1. |
aggregation.sql | For CustomAggregation | The aggregate SQL expression. |
The following monitor tracks the daily sum of my_field and fails when it increases or decreases by more than 5% compared with the previous day:
kind: Metrics
field: my_field
aggregation:
kind: Sum
threshold:
kind: Static
comparisonMode: RelativePercentage
min: -5%
max: 5%
timeWindow:
field: my_time_field
firstRun: P365D
frequency: P1DFor the threshold options (Dynamic with a sensitivity, Static with comparisonMode: Absolute, Relative, or RelativePercentage) and the other shared parameters, see the Thresholds and Parameters references.
Related Templates
- Custom Metrics: Monitors a metric returned by your own SQL query.
- Correlated Metrics: Checks that several metrics stay aligned with each other.
Updated 6 days ago

