Ir para o conteúdo

Lição 24 · Projects and Reference

Project: Data Quality Scorecard

Build a data quality scorecard for a small online shop: define rules, run them with SQL, grade results against targets, list issues and write an owner report.

In this project you build a small but complete data quality scorecard for a fictional online shop. You will define rules, run them in SQL, grade them against targets, list the failing records and write a short report for owners. Everything runs in your browser.

The scenario

The shop's delivery team reports returned parcels, and finance reports order totals that do not match the order lines. Your job is to measure the problem before anyone tries to fix it.

Step 1: Agree on the rules

Before writing SQL, write the rules as business statements with targets:

ID Rule Dimension Severity Target
R1 Every order has a postal code Completeness blocker 100%
R2 Country code exists in the approved list Validity high 100%
R3 Order total equals the sum of its lines Consistency high 100%
R4 Each order number appears once Uniqueness blocker 100%
R5 Shipped orders have a ship date on or after the order date Consistency medium 95%

In a real project, owners approve these. Amounts here are stored as cents in integers, which avoids rounding surprises with decimals.

Step 2: Run the scorecard

The script creates the data, builds one view per rule result and prints the scorecard. Each rule produces one row per checked record with a passed flag of 1 or 0.

SQL Data quality scorecard (SQL)

Press Run (or Ctrl + Enter) to see the result here.

The first table is the scorecard and the second is the work list. Notice that R5 checks only shipped orders, so its denominator differs from the others. Also note that R4 marks both copies of O-104 as failures: you do not yet know which is correct.

Step 3: Write the owner report

Numbers alone do not drive action. Turn results into a short report with impact, likely cause to investigate and next steps.

Python Turn results into a plain-language report

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 4: Extend it

Try these challenges:

  1. Add rule R6: total_cents must be greater than zero.
  2. Add a UK row to the approved list. Should you? The standard ISO 3166-1 code for the United Kingdom is GB, so a better fix is a mapping or fixing the source form.
  3. Add an issue table with owner, severity and due date, and fill it from failures.
  4. Store each run's pass percentage with a date so you can show trends.
  5. Write a one-page rule record for R3, including what happens on failure.

Step 5: Review your work

Check your scorecard against this list:

  • Every rule states its denominator and severity.
  • Blocker rules are visible, not hidden inside an average.
  • Failing records can be listed and traced.
  • Placeholder and empty values count as missing.
  • Nothing in the report claims a cause you have not verified.

Do not edit the data to make the scorecard green. Fix causes at the source, record corrections and measure again.

Reading your results carefully

All five rules are below target in the sample data, which is expected because the data was built with flaws. In real data, interpret results with the same care you apply to any measurement. Six rows are far too few to describe a whole business. A percentage on a tiny set moves a lot when one record changes, so always show the number of checked and failed records next to it.

Also separate symptoms from causes. The scorecard shows that one order total does not match its lines. It does not show why. Possible explanations include a delivery fee stored only on the order, a missing line or a rounding step in another system. Each needs a different fix, and one of them is not an error at all: if fees are legitimate, the rule itself must include them. Ask the steward to check the records before you open a fix.

What to hand over

A finished project has five parts you could give to a colleague:

  1. the rule table, with dimension, severity, denominator and target;
  2. the SQL, with the sample data removed and the source tables named;
  3. the scorecard output with its run date;
  4. the failing record list, shared only with people allowed to see it;
  5. a short report listing next steps and an owner for each.

If you use real data later, avoid putting personal values into the report itself. Use record IDs and let authorized people look up details in the source system.

Make it repeatable

Decide when the scorecard runs, who reads it and what happens when a blocker rule fails. Save each run with its date and the version of the rules. When a rule changes, note it, so that a jump in the trend is not mistaken for a change in the data. A scorecard becomes useful when the same checks run again and someone acts on the result.

Test the rules themselves too. Add one row that should pass every rule and one that should fail a single rule, and confirm that the output matches your expectation. Check what happens with an empty table, because dividing by zero or showing no row at all can make a broken load look harmless. In production, treat a missing result for any expected rule as a failure.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Why does rule R5 have a different number of checked rows from rule R1?

    A rule should be measured only over the records it applies to.
  2. 2. R4 flags both rows with the same order number. Why?

    Investigation is needed before choosing which record to keep.
  3. 3. What is the best way to turn the score green?

    Real improvement comes from fixing causes.

Summary

  • You defined rules with dimension, severity and target.
  • One view of pass and fail flags powered both the scorecard and the work list.
  • Denominators depend on which records each rule applies to.
  • A short report turns results into action without inventing causes.

Next: Project: Governance Starter Kit

Seu progresso fica salvo neste navegador. Não precisa de conta.