15. Data quality 1: measuring it
Data quality is measured, not argued about: profile the data to see what is there, write rules for what the business needs, and score each rule on one of six dimensions.
The clip profiles Kestrel's claims table column by column: how many values are empty, how many are distinct, and the smallest and largest. Three findings light up: claims with no reported date, reserves below zero and in the millions, and more cause codes than Kestrel's list. Then Kestrel's rules score six dimensions (completeness, validity, accuracy, consistency, uniqueness and timeliness), each breached dimension marked, and the rules find exactly the planted defects, with no false alarms on clean data.
The idea: profile, write rules, score them on six dimensions
Measuring quality takes three steps:
- Profile the data before deciding anything: for each column, how many values are empty, how many distinct, the range, the patterns. A profile shows what is there, including what nobody expected.
- Write rules for what the business needs: "a claim has a reported date", "a cause is on the list", "a reserve is between zero and the large-loss limit". Each rule checks rows and gives a score: the share of rows that pass.
- Score each rule on one dimension, so scores can be compared and added up by asset, by domain and by company.
The six dimensions the lab uses:
- Completeness: the value is there.
- Validity: it is allowed (on the list, in the right format).
- Accuracy: it is plausibly true (in a believable range, or matches the real world).
- Consistency: it agrees with other data (the policy a claim names exists).
- Uniqueness: it is recorded once.
- Timeliness: it arrived soon enough to be useful.
A worked example: Kestrel's claims
Profiling Kestrel's 40 claims finds 3 with no reported date, reserves from -50,000 to 990,000,000 cents, and 10 different cause codes where Kestrel's list has 8.
SELECT COUNT(*) AS row_count,
COUNT(*) - COUNT(meldingsdatum) AS meldingsdatum_empty,
COUNT(DISTINCT meldingsdatum) AS meldingsdatum_distinct,
MIN(meldingsdatum) AS meldingsdatum_min,
MAX(meldingsdatum) AS meldingsdatum_max,
COUNT(*) - COUNT(oorzaak_code) AS oorzaak_code_empty,
COUNT(DISTINCT oorzaak_code) AS oorzaak_code_distinct,
COUNT(*) - COUNT(reserve_cent) AS reserve_cent_empty,
COUNT(DISTINCT reserve_cent) AS reserve_cent_distinct,
MIN(reserve_cent) AS reserve_cent_min,
MAX(reserve_cent) AS reserve_cent_max
FROM schadesKestrel's eight rules then score the data: 8 of them are breached, and together they find 19 failing rows, every one of them planted. The reserve rule, as the lab writes it in SQL:
SELECT schade_id AS k FROM schades WHERE NOT COALESCE(reserve_cent BETWEEN 0 AND 10000000, FALSE) ORDER BY schade_id| Dimension | Rules | Breached | Score |
|---|---|---|---|
| Completeness | 1 | 1 | 92.5% |
| Validity | 2 | 2 | 94.2% |
| Accuracy | 1 | 1 | 95.0% |
| Consistency | 2 | 2 | 96.5% |
| Uniqueness | 1 | 1 | 93.3% |
| Timeliness | 1 | 1 | 87.5% |
Why it matters for Alex
"Kestrel's data is bad" is an opinion that stalls a merger. "Kestrel's claims fail six of eight rules, on these rows" is a work list. Alex needs the second, with the rules written down so both companies agree what good means.
Scores by dimension also show where to start: missing reported dates are a broker-portal problem, unknown codes a reference-data problem (chapter 20), duplicates a master-data problem (chapter 18).
Where it goes wrong
- Rules from a template. A hundred generic checks on every column produce a hundred scores nobody needs. Write rules for the uses that matter.
- Untested rules. "A reserve is more than zero" sounds right and flags every closed claim. Test each rule on data where you know the answer.
- One score for everything. An average over all rules hides the one that matters. Keep the dimensions, and keep each rule visible.
- Profiling once. Data changes with every release; profile on a schedule, and before every migration.
Exercises
The lab checks each one against facts written down in advance, so any answer the brief allows passes. A pass is kept in this browser.
Read the profile
Each finding comes from profiling Kestrel's data. Choose the quality dimension it puts at risk.
meldingsdatum is empty on some claims.
reserve_cent runs from below zero to far more than any claim Kestrel insures.
oorzaak_code has more distinct values than Kestrel's list of cause codes.
polis_id values are not in polissen.
klanten have the same name and the same birth date.
Judge the proposed rules
A colleague proposes these rules for Kestrel's data, each for one of the planted defects. Judge each one by what it finds on the data.
Name each rule's dimension
These are Kestrel's eight rules. Choose the dimension each one scores.
On Azure
On Azure, data quality is measured in two places:
- Microsoft Purview's Unified Catalog profiles data assets and runs data quality rules on them (built-in checks such as empty values, uniqueness, formats and freshness, and rules of your own), with scores per asset, data product and governance domain.
- In the pipelines: Azure Databricks' Lakeflow Declarative Pipelines (formerly Delta Live Tables) declare expectations on each table, and Microsoft Fabric notebooks and pipelines can run the same checks in SQL or Python as they load (chapter 17).
- Profiling is in both: Purview's profiles, and the data profile Azure Databricks shows for a table.
Write each rule once, as SQL the lab can test, and run it where the data lands; publish the scores to the catalogue where people look.
Take it to work
Quality rule card
Write one data quality rule so that it can be run, tested and owned.
The rule
- What must be true of each row, in one sentence
- Its dimension
The check
- The SQL, or the tool's rule, that tests it
- The data it was tested on, and what it found
The threshold
- The share of rows that must pass, and why (chapter 16)
The owner
- Who acts when it fails, and what do they do? (chapter 16)
Tools in this chapter
- Quality workbench · Write quality rules, set thresholds, inject defects, and see the scores per dimension and per domain.
Terms taught here: Data qualityData profilingData quality dimensionData quality rule