Data Modeling Best Practices

Chapter 2 · Practice 3 of 4

Make every dimension key NOT NULL and use special members for missing values

From Fact tables

Why it matters

A null foreign key in a fact table drops rows silently from inner joins and shows up as a blank group in reports. Microsoft's guidance recommends setting every dimension key NOT NULL and pointing missing lookups to special dimension members instead:

KeyMeaning
0Missing: not available in the source
-1Unknown: lookup failed during the fact load
-2Not applicable
-3Error

Each special member is a real row in the dimension with readable labels, such as "Unknown customer". Reports then show unknowns as a visible group that someone can investigate, and row counts stay consistent across joins.

Example

SQL
select
    o.order_line_id,
    coalesce(c.customer_key, '-1') as customer_key,  -- -1 = unknown member
    o.quantity,
    o.net_amount
from {{ ref('stg_shop__order_lines') }} as o
left join {{ ref('dim_customers') }} as c
    on c.customer_id = o.customer_id