# Check a table-wide measure

Shape / inspect

A variant of [Check data quality](https://meridian.online/operations/check-data-quality).

Compute one measure over the whole table, such as the row count, share of nulls, mean or age of the newest row, and check it against a threshold.

Page: <https://meridian.online/operations/check-data-quality/check-a-table-wide-measure>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

check row count, null share, mean and age of the newest row against thresholds

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
-- the check is made as of a fixed date, so it gives the same answer on every day it is run
CREATE TEMP TABLE metrics AS
WITH m AS (
  SELECT count(*) AS row_count,
         1 - count(amount) / count(*) AS null_share,
         avg(amount) AS mean_amount,
         DATE '2026-02-15' - max(order_date) AS newest_age_days
  FROM orders)
SELECT 'at least 10 rows' AS rule, row_count AS measured, row_count >= 10 AS passed FROM m
UNION ALL SELECT 'no more than 20% of amounts missing', null_share, null_share <= 0.2 FROM m
UNION ALL SELECT 'mean amount between 200 and 210', mean_amount, mean_amount BETWEEN 200 AND 210 FROM m
UNION ALL SELECT 'newest order at most 7 days old', newest_age_days, newest_age_days <= 7 FROM m;
-- the same check as a gate: HAVING keeps the row only when the measure meets the threshold
CREATE TEMP TABLE gate_passes AS SELECT count(*) AS row_count FROM orders HAVING count(*) >= 10;
CREATE TEMP TABLE gate_fails AS SELECT count(*) AS row_count FROM orders HAVING count(*) >= 11;
SELECT rule, round(measured::DOUBLE, 4) AS measured, passed FROM metrics ORDER BY rule;
SELECT CASE WHEN ((SELECT map_from_entries(list((rule, passed) ORDER BY rule)) FROM metrics) = MAP {'at least 10 rows': true, 'mean amount between 200 and 210': false, 'newest order at most 7 days old': true, 'no more than 20% of amounts missing': true} AND (SELECT measured::DOUBLE FROM metrics WHERE rule LIKE 'newest%') = 5 AND (SELECT round(measured::DOUBLE, 4) FROM metrics WHERE rule LIKE 'mean%') = 211.1933 AND (SELECT round(measured::DOUBLE, 2) FROM metrics WHERE rule LIKE 'no more%') = 0.1 AND (SELECT count(*) FROM gate_passes) = 1 AND (SELECT count(*) FROM gate_fails) = 0) THEN 'as expected' ELSE error('the four table-wide measures should be 10 rows, 0.1 null share, a mean of 211.1933 (outside 200 to 210) and a newest row 5 days old, and HAVING should pass at 10 and fail at 11') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- dbt-utils: [`at_least_one`](https://raw.githubusercontent.com/dbt-labs/dbt-utils/main/README.md) (read 2026-09-27)
- dbt-utils: [`not_constant`](https://raw.githubusercontent.com/dbt-labs/dbt-utils/main/README.md) (read 2026-09-27)
- dbt-utils: [`not_null_proportion`](https://raw.githubusercontent.com/dbt-labs/dbt-utils/main/README.md) (read 2026-09-27)
- dbt-utils: [`recency`](https://raw.githubusercontent.com/dbt-labs/dbt-utils/main/README.md) (read 2026-09-27)
- Duckle: [`Freshness Check (SLA Gate)`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- Duckle: [`Run Baseline`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- AWS Glue: [`Completeness`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`DataFreshness`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`DistinctValuesCount`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`Mean`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`RowCount`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`StandardDeviation`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`Sum`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`UniqueValueRatio`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- AWS Glue: [`Uniqueness`](https://docs.aws.amazon.com/glue/latest/dg/dqdl-rule-types.html) (read 2026-09-27)
- Apache Hop: [`Evaluate rows number in a table`](https://hop.apache.org/manual/latest/workflow/actions/evaluatetablecontent.html) (read 2026-09-27)
- SQLMesh: [`at_least_one`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`chi_square`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`kl_divergence`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`mean_in_range`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`not_constant`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`not_null_proportion`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`number_of_rows`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
- SQLMesh: [`stddev_in_range`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/audits.md) (read 2026-09-27)
