Skip to main content
A metric is one number Hatchmark can compute for any period and any group: revenue, orders, refund rate. Each lives in its own file under metrics/, and the file name is the metric’s name: metrics/refund_rate.yaml is refund_rate. Names are lowercase snake_case. Dashboards refer to metrics by name, so a metric means the same thing on every dashboard. Print the full JSON Schema with hatchmark schema metric. Every metric has these fields:

aggregate

Aggregates one column of a source, after optional filters.
Only sum and count add up across groups, so only they can show a percent of total in a table (HM4001 otherwise).

ratio

A ratio divides two other metrics: numerator / denominator, both metric names. It has no table, filters or time of its own; it reads its period and groups through the two metrics, which may come from different sources. Both sides need a time column, or neither. Totals divide the two totals (never an average of the rows’ ratios), and a division by zero or by an empty value is empty, shown as —. Refund rate, the most common shape, takes three files. The two counts: metrics/refunded_orders.yaml
metrics/placed_orders.yaml
and the ratio, metrics/refund_rate.yaml:
A percent metric holds a fraction (0.059 shows as 5.9%), so its KPI change is in percentage points (▼ −0.99 pp), and better: "down" colours a fall as good. Average order value is the same shape: numerator: revenue, denominator: orders, currency format, better: "up".

sql

The escape hatch, for a number no aggregate expresses: one SQL aggregate expression over one source.
Write SQL longer than a line as a block scalar: sql: | and the expression indented on the lines below, exactly as it reads. additive is true only if summing the metric over groups gives the metric over all rows (a sum or a count). Distinct counts, averages and ratios are false. A group or bucket with no rows shows what the SQL gives over no rows, such as 99 for coalesce(sum(amount), 99) or 7 for coalesce(avg(amount), 7); an additive metric whose SQL gives null there shows 0. Build warns with HM4003 when a table’s rows do not add up to its total. filters and time work as for an aggregate. $hm_p is reserved for the parameters Hatchmark binds, in any case and anywhere in sql, inside strings too. check rejects it with HM3005.

Filters

A filter keeps the rows whose column matches. All filters of a metric must match. neq and not_in keep rows whose column is empty; the other operators never match an empty value. Dates are YYYY-MM-DD and match the whole local day. Numbers has the exact rules.

Targets

A target is a goal for a metric, set once in the metric file so every block that shows the metric can show it. A block names one with target: <id> (kpi, line, area and bar blocks): a KPI shows its attainment and a progress bar, a line or area a dashed target line, and a bar a target tick.
A date inside a bucket counts for that bucket. A bucket whose value rows are all empty has no value, while an explicit 0 is 0. A table must be a file source for now: a lookup source as a target’s table is not evaluated yet, so the block shows no target and build warns with HM4023. Flow targets (sums and counts over a period) are amounts per bucket.
  • A coarser bucket is the sum of the target buckets inside it, and has a target only when every one of them has a value: a quarter needs all three months.
  • A finer bucket, or a bucket that crosses target buckets (weeks against months), gets each target bucket in proportion to its days inside: a week of January gets 7/31 of January’s target. check notes this with HM4022. prorate: none shows the target only where its buckets fit whole and hides it at finer grains.
  • A KPI or category bar reads the target over its window’s period, prorated by days at the edges, and only when every target bucket the period touches has a value; otherwise it shows no target and build warns with HM4020. The period is the whole bucket of a to-date range (all of November for month to date), the window itself for last N ranges, and the range as written otherwise.
  • When the window ends before its period does (a to-date range at the horizon, or a range the horizon trims), the target also carries a pace: the target times the share of the period elapsed, in local wall-clock time, so a month-to-date KPI on November 26 at 2 p.m. is compared with 25.58 of 30 days. A time series’ partial bucket has a pace the same way, by its own elapsed share.
  • A metric that doesn’t add up over time (an average, a ratio) has a target only at its own grain, never summed or split, and no pace: its attainment is the value over the target. Point-in-time targets have no pace either.
Point-in-time targets (balances, ARR) are values at the end of each bucket. Between two values the target moves in a straight line (linear) or by a constant growth factor (compound, which needs both values positive). There is no target before the first value’s bucket end, nor after the last one’s. A bucket reads the target at its end, the bucket the horizon cuts reads it at the horizon, and a KPI reads it at its window’s end. Filters and segments. A table target follows the dashboard’s select filters and segment toggles when its table has their columns, and splits by a block’s by or split column when its table has that column: each bar and each split series then has its own target. Otherwise the block shows the target for the whole metric. When a select filter keeps some values of a column the target’s table lacks (inline values have no columns), or a segment is on that the target cannot follow, the block hides the target and says why; check warns ahead of time with HM4021. A target that lists its segments is shown while only those segments are on, without being filtered again.

Tests

tests pins values of the metric so that hatchmark test fails when the data or the definition changes them. Each test reads the metric the way a dashboard does, through the same queries:
A test that fails is HM4030 with the expected and actual values and the difference. Without by, its fix rewrites expect and is unsafe, so say when you change a pinned number. check reports a column in where or by that a source the metric reads doesn’t have (HM2018); with data, the columns are checked against the fixture when the test runs. A test whose window reaches past the newest data of a source it reads gets warning HM4031: the number can still change.

Format

KPIs switch large currency values to compact notation at 100,000 and plain numbers at 1,000,000 on their own. Tables show the full value unless compact is true. A compact value is rounded only when the result shows a unit such as K, Mio. or 万; when the locale’s compact form has no unit for it, the full value is shown instead. A value can round up into a unit (999,500 is 1 Mio. $ in de-DE). Where an exact value is too long for a chart, bar charts leave out their inline values and a donut states its total in the key; tooltips keep the value.