Measuring data quality is the practice of turning "is this data fit for use" into numbers you can compute on a schedule, compare over time, and act on when they move.
That last clause is the one most dashboards fail. A single 0 to 100 "data quality score" in green is easy to build and almost impossible to act on. When it drops from 97 to 94, nobody knows which table, which check, or whether anyone downstream is affected. When it stays at 97 while the revenue table is broken, it's worse than useless, because it told leadership everything was fine.
This post gives you six metrics that are concrete enough to compute from warehouse metadata, with SQL for Snowflake and Databricks, plus a scorecard that decides which of them go in front of leadership and which stay with the team. It assumes you know the six dimensions of data quality already. Dimensions tell you what can go wrong. Metrics tell you how much it went wrong this week.
Why are most data quality scores vanity metrics?
A metric is vanity if it can improve without the data getting better, or if nobody changes what they do when it moves. Most composite quality scores fail both tests, for three structural reasons.
Averaging hides the failure that matters. Take 400 tables. 399 of them score 100 and the table behind the revenue dashboard scores 0 because it hasn't loaded since Tuesday. The average is 99.75. Round it and you're reporting 100% to a CFO whose board deck is wrong. Any score that averages across tables of different importance has this bug, and weighting doesn't fully fix it, because a weighted average still lets ten healthy tables compensate for one broken one.
The denominator is self-selected. Test pass rate is the classic case. Picture 2,000 dbt tests, 1,600 of which are not_null and unique on primary keys that have never failed. Six tests fail this week. The pass rate is 99.7%. Those 6 failures might all be on one critical model, and the number still looks excellent. Worse, you can raise the score by adding more easy tests, which is exactly the behavior a metric should never reward.
Coverage gets confused with quality. "We monitor 85% of tables" is a statement about your monitoring, not your data. It's a useful number, but it belongs on an engineering to-do list, not a quality report.
AnomalyArmor deliberately doesn't ship a single quality grade. What it ships is a coverage score: a 0 to 100 number weighted 30 points for freshness coverage, 25 for metrics, 15 for schema drift, 15 for alert routing, 10 for validity, and 5 for an up-to-date knowledge base. Its own docstring says partial coverage in one area compensates for gaps in another. That's the right design for a coverage number, because it's a checklist of what to set up next. It would be the wrong design for a quality number, for the averaging reason above, and that's why it's called coverage.
What should you measure instead?
Six metrics, each tied to a dimension, each computable on a schedule without a human deciding what the answer should be.
| Metric | Dimension | Computed from | Cost to compute | Operate or report? |
|---|---|---|---|---|
| Freshness lag ratio | Timeliness | information_schema.tables.last_altered | Metadata only | Operate (feeds uptime) |
| Volume deviation | Completeness | Daily row count snapshots | Metadata on Snowflake, COUNT(*) on Databricks | Operate |
| Schema change count | Validity, consistency | Daily information_schema.columns snapshots | Metadata only | Operate |
| Null rate drift | Completeness | Scan of new rows on critical columns | One scan per column per load | Operate |
| Test pass rate | Validity, uniqueness | dbt run_results.json | Free, already produced | Operate, never report |
| TTD and TTR | All (outcome) | Incident log | Free if you log incidents | Report |
Two composites sit on top of these: tier-1 uptime and detection share. Those are the numbers that go upward, and they're covered in the scorecard section below.
Notice what's missing. Accuracy has no row. You can't measure accuracy from metadata, because accuracy means agreement with the real world, and the warehouse doesn't know what the real world looks like. The only honest accuracy metric I know is a reconciliation check on the 3 to 5 numbers the business actually runs on: warehouse revenue against the billing system, active customers against the CRM. Anything that claims to score accuracy across 400 tables automatically is scoring something else and calling it accuracy.
Every metric below writes to a small dq schema. That's deliberate. Most of these need history to mean anything, and information_schema only tells you about now.
How do you measure freshness lag?
Freshness lag is the time since a table last changed, divided by how often it's supposed to change. The ratio matters more than the raw lag. A table that's 6 hours old is fine if it loads daily and broken if it loads every 15 minutes.
Start with a declared SLA per table. You don't need one for every table, only the ones somebody would page about:
-- Snowflake and Databricks (qualify dq as main.dq on Databricks) CREATE TABLE IF NOT EXISTS dq.table_sla ( table_fqn STRING, -- catalog.schema.table; uppercase on Snowflake tier INT, -- 1 = someone gets paged, 2 = someone gets told sla_minutes INT -- max acceptable minutes since last change ); Then record the lag every hour. On Snowflake, INFORMATION_SCHEMA.TABLES carries LAST_ALTERED:
-- Snowflake: run hourly from a task INSERT INTO dq.freshness_checks (checked_at, table_fqn, lag_minutes, freshness_ratio) SELECT CURRENT_TIMESTAMP(), s.table_fqn, DATEDIFF('minute', t.last_altered, CURRENT_TIMESTAMP()), DATEDIFF('minute', t.last_altered, CURRENT_TIMESTAMP()) / s.sla_minutes FROM analytics.INFORMATION_SCHEMA.TABLES t JOIN dq.table_sla s ON s.table_fqn = t.table_catalog || '.' || t.table_schema || '.' || t.table_name; On Databricks with Unity Catalog, each catalog's information_schema.tables has a last_altered column too. Databricks documents it as when the relation definition was last altered, so before trusting it for data writes, check it against DESCRIBE HISTORY on a table you know just loaded:
-- Databricks: run hourly from a job INSERT INTO main.dq.freshness_checks SELECT current_timestamp(), s.table_fqn, timestampdiff(MINUTE, t.last_altered, current_timestamp()), timestampdiff(MINUTE, t.last_altered, current_timestamp()) / s.sla_minutes FROM main.information_schema.tables t JOIN main.dq.table_sla s ON s.table_fqn = concat_ws('.', t.table_catalog, t.table_schema, t.table_name); A ratio above 1.0 is a breach. A ratio of 0.8 that was 0.3 last week is a pipeline slowing down, and that's the more valuable signal because you can act on it before anyone notices.
One caveat worth knowing. Snowflake documents LAST_ALTERED as changing on DML, DDL, or background metadata operations, so a table can look fresher than its data really is. If a table's freshness matters enough to be tier 1, it's worth swapping the metadata timestamp for MAX(loaded_at) on the table itself. On Databricks, DESCRIBE HISTORY gives you the actual Delta commit timestamps when you need to confirm what last_altered is telling you. The freshness monitoring post covers the column-based approach in more depth.
How do you measure volume deviation?
Volume deviation is how far today's row growth is from the typical row growth on the same weekday, expressed as a fraction. Use rows added, not total rows. A table with 400 million rows that received zero new rows today has a total row count that moved 0%, which is how a dead pipeline hides inside a big table.
The snapshot is where the two platforms differ most. Snowflake keeps a row count in metadata, so the snapshot is one statement:
-- Snowflake: run daily CREATE TABLE IF NOT EXISTS dq.table_snapshots ( snapshot_date DATE, table_fqn STRING, row_count NUMBER, last_altered TIMESTAMP_LTZ ); INSERT INTO dq.table_snapshots SELECT CURRENT_DATE(), table_catalog || '.' || table_schema || '.' || table_name, row_count, last_altered FROM analytics.INFORMATION_SCHEMA.TABLES WHERE table_type = 'BASE TABLE' AND table_schema <> 'INFORMATION_SCHEMA'; Databricks' information_schema.tables has no row count column, so you count. On Delta, an unfiltered COUNT(*) can usually be answered from the statistics in the transaction log rather than a full scan, so this is cheaper than it looks:
# Databricks notebook: run daily as a job from datetime import date tables = spark.sql(""" SELECT table_catalog, table_schema, table_name, last_altered FROM main.information_schema.tables WHERE table_schema <> 'information_schema' AND table_type IN ('MANAGED', 'EXTERNAL') """).collect() rows = [] for t in tables: fqn = f"{t.table_catalog}.{t.table_schema}.{t.table_name}" quoted = f"`{t.table_catalog}`.`{t.table_schema}`.`{t.table_name}`" n = spark.sql(f"SELECT COUNT(*) AS n FROM {quoted}").first().n rows.append((date.today(), fqn, n, t.last_altered)) schema = "snapshot_date date, table_fqn string, row_count bigint, last_altered timestamp" spark.createDataFrame(rows, schema).write.mode("append").saveAsTable("main.dq.table_snapshots") Once snapshots exist, the deviation query is the same on both platforms. MEDIAN, LAG, DATEADD, and DAYOFWEEK exist in Snowflake and in Databricks SQL (MEDIAN needs Databricks Runtime 11.3 or later, or a SQL warehouse):
-- Snowflake and Databricks: volume deviation vs same weekday, trailing 8 weeks WITH daily AS ( SELECT snapshot_date, table_fqn, row_count - LAG(row_count) OVER (PARTITION BY table_fqn ORDER BY snapshot_date) AS rows_added FROM dq.table_snapshots ), baseline AS ( SELECT table_fqn, MEDIAN(rows_added) AS median_added FROM daily WHERE snapshot_date >= DATEADD(DAY, -56, CURRENT_DATE()) AND snapshot_date < CURRENT_DATE() AND DAYOFWEEK(snapshot_date) = DAYOFWEEK(CURRENT_DATE()) GROUP BY table_fqn ) SELECT d.table_fqn, d.rows_added, b.median_added, ROUND((d.rows_added - b.median_added) / NULLIF(b.median_added, 0), 3) AS volume_deviation FROM daily d JOIN baseline b ON b.table_fqn = d.table_fqn WHERE d.snapshot_date = CURRENT_DATE() ORDER BY ABS(volume_deviation) DESC NULLS LAST; A deviation of -1.0 means nothing arrived. A deviation of +1.0 means double the usual load, which is usually a duplicate backfill. I'd start alerting at plus or minus 0.5 on tier-1 tables and tune from there. Same-weekday comparison matters: plenty of B2B tables load 70% fewer rows on Sunday, and a plain trailing average flags every one of those as an anomaly.
How do you count schema changes?
Schema change count is the number of columns added, dropped, or retyped per table per day. It's the cheapest metric on this list and, in my experience, the one most correlated with incidents that start upstream of you.
Snapshot the column list daily. The insert differs by platform only in naming:
-- Snowflake: run daily INSERT INTO dq.column_snapshots (snapshot_date, table_fqn, column_name, data_type) SELECT CURRENT_DATE(), table_catalog || '.' || table_schema || '.' || table_name, column_name, data_type FROM analytics.INFORMATION_SCHEMA.COLUMNS WHERE table_schema <> 'INFORMATION_SCHEMA'; -- Databricks: run daily INSERT INTO main.dq.column_snapshots SELECT current_date(), concat_ws('.', table_catalog, table_schema, table_name), column_name, data_type FROM main.information_schema.columns WHERE table_schema <> 'information_schema'; The diff runs unchanged on both:
-- Snowflake and Databricks: schema changes since yesterday WITH today AS ( SELECT * FROM dq.column_snapshots WHERE snapshot_date = CURRENT_DATE() ), yday AS ( SELECT * FROM dq.column_snapshots WHERE snapshot_date = DATEADD(DAY, -1, CURRENT_DATE()) ) SELECT COALESCE(t.table_fqn, y.table_fqn) AS table_fqn, SUM(CASE WHEN y.column_name IS NULL THEN 1 ELSE 0 END) AS columns_added, SUM(CASE WHEN t.column_name IS NULL THEN 1 ELSE 0 END) AS columns_dropped, SUM(CASE WHEN t.data_type <> y.data_type THEN 1 ELSE 0 END) AS types_changed FROM today t FULL OUTER JOIN yday y ON t.table_fqn = y.table_fqn AND t.column_name = y.column_name GROUP BY COALESCE(t.table_fqn, y.table_fqn) HAVING SUM(CASE WHEN y.column_name IS NULL OR t.column_name IS NULL OR t.data_type <> y.data_type THEN 1 ELSE 0 END) > 0; Don't treat all changes equally. An added nullable column breaks almost nothing. A dropped column or a type change from NUMBER to VARCHAR breaks every model that selects it. The operating metric is all changes; the number worth tracking monthly is breaking changes on tier-1 sources that nobody announced, because that's the number that tells you whether you need a data contract with the team upstream.
How do you measure null rate without scanning the whole table?
Null rate drift is the change in the share of null values in a critical column, measured on the newly loaded rows only, compared against that column's usual rate. This is the one metric here that needs a real scan, so it should only run on columns that would break something if they went null.
Measure the new rows, not the table. If a 3-year table gets one bad day where 40% of customer_id values are null, the table-wide null rate moves by about 0.04 percentage points. You'll never see it. The same bad day measured on the day's load jumps from, say, 0.1% to 40%.
COUNT_IF exists in both Snowflake and Databricks SQL, so one query covers both:
-- Snowflake and Databricks: null rate on the last day's load INSERT INTO dq.null_rates SELECT CURRENT_DATE() AS snapshot_date, 'analytics.core.orders' AS table_fqn, COUNT(*) AS rows_checked, COUNT_IF(customer_id IS NULL) / COUNT(*) AS customer_id_null_rate, COUNT_IF(amount IS NULL) / COUNT(*) AS amount_null_rate FROM analytics.core.orders WHERE loaded_at >= DATEADD(DAY, -1, CURRENT_TIMESTAMP()); Drift is today's rate minus the trailing median rate, in percentage points. Report it in points rather than as a relative change. A column going from 0.01% to 0.03% null is a 200% increase and almost certainly nothing. A column going from 2% to 12% is a 10-point jump and almost certainly a broken join or a source that stopped sending a field.
Is test pass rate a useful data quality metric?
As an operating signal, yes. As a reported KPI, no, for the denominator reason already covered. The failing tests matter; the percentage doesn't.
dbt writes every result to target/run_results.json, so you already have the data. This pulls out what's actually useful:
import json from collections import Counter with open("target/run_results.json") as f: results = json.load(f)["results"] tests = [r for r in results if r["unique_id"].startswith("test.")] status = Counter(r["status"] for r in tests) evaluated = status["pass"] + status["fail"] + status["warn"] + status["error"] print(f"tests evaluated: {evaluated}") print(f"pass rate: {status['pass'] / max(evaluated, 1):.1%}") print(f"failing: {status['fail'] + status['error']}") print(f"warning: {status['warn']}") for r in tests: if r["status"] in ("fail", "error", "warn"): print(f" {r['status']:<5} {r['unique_id']} failures={r.get('failures')}") The line that matters is the warning count. Tests set to severity: warn don't fail the run, so they pile up silently. A team with 40 standing warnings has 40 known problems that its pass rate is quietly counting as fine. I'd report warnings separately from failures every time, and treat a warning count that only grows as its own incident.
If you want a test-based number that resists gaming, use "tier-1 models with at least one failing or warning test." It's a count of tables, it can't be inflated by adding trivial tests, and it maps to something a human can fix.
How do you measure TTD and TTR?
Time to detection is how long a problem existed before anyone knew. Time to resolution is how long it took to fix once known. Data downtime combines them, and that post covers the formula and cost model. What it doesn't cover is the part that makes TTD hard to measure honestly: the start time.
Detection and resolution timestamps are easy because a system records them. Onset is never recorded, because by definition nothing noticed it. You have to infer it, and the inference rule depends on the failure type:
| Failure type | Infer onset as | Why |
|---|---|---|
| Freshness breach | last_altered + sla_minutes | The moment the table became late |
| Volume drop | The scheduled load time of the bad snapshot | The load that came in short |
| Schema change | First snapshot showing the change, minus 24 hours | Bounded by snapshot resolution |
| Bad values (nulls, ranges) | MIN(loaded_at) of the affected rows | The first bad row is the start |
| Human-reported | Back-check the metrics above | Otherwise you'll record TTD as zero |
The last row is where most incident logs lie. When a stakeholder reports a broken dashboard, someone opens an incident and the detection time equals the report time. If onset isn't back-filled, the TTD for the worst incidents, the ones monitoring missed entirely, gets recorded as roughly zero. Your median TTD looks great precisely because your monitoring failed.
AnomalyArmor's incident record has the same gap, for the same reason. It stores when an incident was first detected, acknowledged, and resolved, so TTR falls straight out of it. It has no onset field, so TTD still needs one of the inference rules above.
Given an incident log with an inferred started_at, one query gives you the reportable numbers. Use the median and 90th percentile rather than the mean, because one 3-day incident will dominate an average of twenty 1-hour ones:
-- Snowflake and Databricks: incident metrics, trailing 90 days SELECT COUNT(*) AS incidents, MEDIAN(TIMESTAMPDIFF(MINUTE, started_at, detected_at)) AS median_ttd_min, PERCENTILE_CONT(0.9) WITHIN GROUP ( ORDER BY TIMESTAMPDIFF(MINUTE, started_at, detected_at) ) AS p90_ttd_min, MEDIAN(TIMESTAMPDIFF(MINUTE, detected_at, resolved_at)) AS median_ttr_min, AVG(CASE WHEN detected_by = 'monitor' THEN 1.0 ELSE 0.0 END) AS detection_share FROM dq.incidents WHERE started_at >= DATEADD(DAY, -90, CURRENT_TIMESTAMP()) AND resolved_at IS NOT NULL; Count incidents by root cause, not by alert. If one broken connector produces thirty alerts across thirty downstream tables, that's one incident with one TTD. Counting it as thirty inflates incident volume and deflates TTD, since the downstream alerts fire after the root. The alert storm post covers how to group them.
Which metrics should you report to leadership?
Three. Everything else in this post stays with the team.
This is the scorecard. I call it the weakest-link scorecard because its core rule is that nothing averages across checks: a table is up in a given hour only if every check on it passes.
1. Tier-1 uptime. For each tier-1 table, each hourly freshness check counts as an up-hour only if the table is within its SLA and has no open incident. Uptime is up-hours divided by checked hours.
Tier-1 uptime = up-hours / checked hours, across all tier-1 tables up-hour = freshness_ratio <= 1.0 AND no open incident on the table Volume, schema, null, and test failures enter through the incident clause. When any of them opens an incident against a table, that table is down until the incident resolves. That's the weakest-link part: a table with perfect freshness and a broken amount column is down, because it is.
-- Snowflake and Databricks: tier-1 uptime, trailing 30 days WITH checks AS ( SELECT f.table_fqn, f.checked_at, MAX(CASE WHEN f.freshness_ratio <= 1 THEN 1 ELSE 0 END) AS fresh, MAX(CASE WHEN i.incident_id IS NOT NULL THEN 1 ELSE 0 END) AS has_incident FROM dq.freshness_checks f JOIN dq.table_sla s ON s.table_fqn = f.table_fqn AND s.tier = 1 LEFT JOIN dq.incidents i ON i.table_fqn = f.table_fqn AND f.checked_at >= i.started_at AND f.checked_at < COALESCE(i.resolved_at, CURRENT_TIMESTAMP()) WHERE f.checked_at >= DATEADD(DAY, -30, CURRENT_TIMESTAMP()) GROUP BY f.table_fqn, f.checked_at ) SELECT table_fqn, ROUND(AVG(CASE WHEN fresh = 1 AND has_incident = 0 THEN 1.0 ELSE 0.0 END), 4) AS uptime, SUM(CASE WHEN fresh = 1 AND has_incident = 0 THEN 0 ELSE 1 END) AS down_hours FROM checks GROUP BY table_fqn ORDER BY uptime ASC; Report two numbers from this: the overall uptime and the worst table. "Tier-1 uptime was 99.4%, worst table fct_revenue at 96.1%" is a sentence a VP can act on. 99.4% alone isn't. At hourly checks, 30 days is 720 hours per table, so 96.1% means about 28 hours down, and you can say that too.
2. Detection share. The fraction of incidents your monitoring caught before a human reported them. This is the single best measure of whether monitoring is working, and it's nearly impossible to game: the only way to raise it is to catch more things first. A te...

