Skip to main content
You will end with three metrics on a refunds source: an amount, a count and a rate, each checked against the numbers it should give and pinned by a test. The steps assume the refunds source from Connect your data, with refunded_at and amount columns.

1. Sum a column

Every file under metrics/ is one metric, named after the file. Create metrics/refunded_amount.yaml:
  • table names the source and column what to add up.
  • time is the date that places a row in a period. Set it on almost every metric.
  • better: down colours a rise red on every KPI.

2. Count rows

metrics/refunds.yaml counts rows, so it needs no column:
filters keeps only some rows, such as status: paid in the sample orders metric. See filters.

3. Divide two metrics

A rate is a ratio of two metrics, here the refunds over the sample project’s orders. Create metrics/refund_rate.yaml:
A ratio divides the totals for each period and group, so a quarter’s rate is that quarter’s refunds over its orders, never an average of monthly rates.

4. Check the numbers

query computes values exactly as a dashboard card does. Compare one against a number you trust, such as a total from hatchmark data query. hatchmark explain refund_rate prints the SQL behind it.

5. Pin a value

Add a test with the value you checked, so hatchmark test fails when a change to the data or the definition moves it:
Tests also pin values per group and against fixture files.

Next

  • Build a dashboard with the new metrics.
  • Metrics lists every metric type: sql, formula, per_entity and point-in-time metrics over snapshots.