Skip to content

Data quality: how to measure and improve it

B2Bnetwork team · · 6 min

Integrations, data and cloud

In brief

Data quality is measured with rules that return a number: the percentage of records that are complete, valid, consistent, timely and unique. Each rule has a threshold, an owner and a place in the data pipeline where it is checked automatically. Improvement means removing causes in the source system, not manually cleaning a report before every month-end close. Start with the data that feeds regulatory reports or decisions about money.

Data quality dimensions you can measure

“The data is of poor quality” is not a diagnosis. A diagnosis sounds like this: “8% of contracts have no branch assigned” or “the balance in the data warehouse differs from the general ledger by 0.3% of the total”. To talk like that, you need dimensions that translate into rules.

DimensionQuestionExample rule
Completenessis the required field filled inevery policy has a coverage start date
Format validitydoes the value have the right forma company tax ID (NIP) has 10 digits and a valid checksum
Accuracyis the value truethe customer's address matches the registry
Consistencyis the same information in two places the samethe sum of transactions in the warehouse equals the sum in the source system
Timelinessis the data on timemeter readings from the previous day are in the platform by 6:00
Uniquenessdoes the object appear only onceone customer has one identifier, not three records
Integritydo the links existevery transaction points to an existing account

Accuracy is the hardest to measure automatically, because it requires an external source of truth. The other dimensions can be checked with a query on every data load.

How to turn a dimension into a measure

A quality rule is a query that returns the number of records meeting a condition and the number of all records. An example for completeness, format and uniqueness in a table of corporate customers (PostgreSQL syntax):

SELECT
  COUNT(*) AS total,
  COUNT(*) FILTER (WHERE tax_id IS NULL) AS missing_tax_id,
  COUNT(*) FILTER (WHERE tax_id IS NOT NULL AND tax_id !~ '^\d{10}$') AS bad_format_tax_id,
  COUNT(tax_id) - COUNT(DISTINCT tax_id) AS duplicate_tax_id
FROM corporate_customers
WHERE load_date = CURRENT_DATE;

The result is stored in a measurement history table: date, rule, number of errors, number of records. This shows the trend, not just today's state, and lets you say whether a change in the source system improved the situation. Writing such queries is a basic skill for a data analyst.

Every rule needs a threshold and a reaction. Example: below 0.5% missing values the load passes and raises a warning, above 2% the load stops and the data owner is notified. Thresholds are set with the data consumers, because they know how many errors a report can tolerate.

Where to measure: at the source, in the pipeline and in the report

Rules are placed in three locations, because each catches different errors:

  1. At the source. Validation in a form or in the API of the system that creates the data. The cheapest place, because the error never arises. This is where formats, dictionaries and required fields are fixed.
  2. In the data pipeline. Tests on every load into the warehouse or data platform. They catch integration errors, for example a changed file format, a missing batch of data, or duplicated records after a job is rerun.
  3. In the report. Reconciliation of control totals with the source system, for example the sum of balances in the warehouse against the general ledger. This is the last line of defense before a wrong report is sent to the regulator.

In pipelines built with dbt, rules are written as data tests alongside the models. Built-in tests check, among other things, uniqueness, absence of null values, accepted values and the existence of related records, and custom rules are written in SQL. Other data testing tools have similar mechanisms; the choice of tool matters less than whether the tests run on every load.

When data flows between systems in near real time, for example through Change Data Capture, rules are checked on the stream, and bad records go to a separate queue for investigation instead of blocking the whole flow.

The data owner and the improvement process

Measurement without an owner ends up as a report nobody reads. Every dataset important to the company has a person on the business side who decides what “a correct record” means, and a team that fixes causes in the source system.

The improvement process usually looks like this:

  • a rule detects an error and creates a ticket with sample records;
  • the owner assesses the impact: does the error reach a report, a credit decision, a settlement;
  • the source system team removes the cause, for example by adding validation or fixing the integration;
  • existing bad records are corrected once, with a script that logs the changes;
  • the rule stays in the pipeline and makes sure the error does not return.

Manually correcting data in the warehouse before every report is the most expensive option: it costs effort every month, leaves no trail and hides the problem from the team that could fix it.

Where to start at a bank, an insurer and a factory

Start with the data that goes into regulatory reports or decisions about money. At a bank this is usually data for supervisory reporting, described in the scenario a data warehouse for FINREP reporting. At an insurer it is data for solvency reporting, and in energy and industry it is readings from devices, where a gap in the data means a wrong settlement or a false alarm. The choice of architecture in which this data lives is discussed in the article Data warehouse, data lake or lakehouse at a bank.

For the first dataset, a dozen or so rules, a measurement history table and one simple view with a trend are enough. Expansion comes when teams start using it.

Questions and answers

What level of data quality is sufficient?

One at which a decision or a report based on the data stays correct. For a regulatory report the tolerance can be close to zero, while for a marketing analysis a few percent of missing values does not change the conclusion. That is why thresholds are set separately for each use, together with the data consumer, not as a single indicator for the whole company.

Is data quality a task for the IT team?

Partly. IT builds the measurements, pipeline tests and validations in systems. What a correct value means and how many errors are acceptable is decided by the business, because it knows the consequences of an error. Without an owner on the business side, rules are either too loose or block loads for no reason.

How do you measure the quality of test data?

With the same rules as production data, because test data that does not meet production rules gives false test results. In addition, check whether the data kept the relationships between tables after anonymization. The principles of preparing such data are described in the article Test data and GDPR.

Will an AI model help improve data?

It can help detect duplicates, complete dictionaries and flag suspicious records, for example addresses written in several ways. A decision to correct data important for settlements, however, should be approved by a person, and every change must leave a trail. A model also does not replace validation at the source, which prevents errors.

What it looks like in a project

Connecting systems or moving them to the cloud? Talk to an architect.

Let's talk

Read more: Integrations, data and cloud