Data quality tests
NWOrders NWOrderLines NWReturns NWFx RawOrdersExport- Why it matters
- Every report inherits the quality of its data. Tests that run on every load catch duplicates, orphans and impossible values before an executive does.
- Typical production failure
- A re-run export duplicates 37 lines; nobody notices for a quarter because the totals "looked about right".
- When to use it
- Uniqueness of keys, non-null required columns, referential integrity, valid ranges, row-count and total reconciliation with the source, and freshness. Run them on every load; fail loudly.
- When not to
- Testing only in Power Query by eye. Tests that aren't automated stop being run.
Assignments
A data quality suite for the company pack
Write one query (or one script) that runs a set of named data quality tests and returns, for each, the number of failing rows. It must run after every load and be easy to read.
- Uniqueness of (OrderID, LineNo) in order_lines.
- Referential integrity: lines and returns point to existing orders.
- Valid ranges: quantity > 0; returned quantity not above the sold quantity; ship date not before order date.
- Every EUR order month has an exchange rate.
- Flag test customers.
Reconcile row counts and totals, source to model
For the Beginner clean-up of RawOrdersExport, write the reconciliation that proves where every source row went: kept, removed as header or total, or removed as a duplicate.
- Row counts at each step.
- A check that kept + removed = source.
- Where you would put this so it runs on every refresh.
Which tests should block a release?
Elena asks you to classify data tests into "block the load", "warn and continue" and "report weekly". There is no single right answer: justify yours.
- Duplicate keys in a fact.
- A dimension member missing for some facts.
- A 15% drop in daily row count.
- Nulls in an optional column.
- A refresh finishing 30 minutes later than usual.
Interview questions
- Which data quality tests would you always run on a fact table?
- Where should data quality tests run?
- What's the difference between a failed test and a known defect?
- Why reconcile counts, not just totals?
Assessment
A fact table's key isn't unique. The safest treatment is:
- Ignore it
- Fail the load and investigate
- Average the duplicates
- Remove the key column
Sales lines reference a product that isn't in DimProduct. Best practice:
- Drop those lines
- Map them to an Unknown product member and report the count
- Delete the product dimension
- Use a bi-directional relationship
Add a Data Quality page to your Sprint 01 report: one card per test with its failing-row count, red when above zero.
Measures like COUNTROWS(FILTER(VALUES(FactSales[LineKey]), CALCULATE(COUNTROWS(FactSales)) > 1)) for duplicates; keep it on a hidden or admin page.