EX-2: SCD Type 2 Temporal Joins: Fix the £8M Cash ISA Discrepancy
Track: Architecture & Modeling • Difficulty: Intermediate • Mastery Points: 150 PTS
Business Problem Scenario
Global DynaDatum Bank's executive board pack dropped £8,000,000.00 in reported savings liabilities on May 31, 2026, triggering an urgent Treasury audit. An investigation revealed that 3,000 Cash ISA accounts were misclassified as 'Investments' instead of 'Savings'. On July 1, 2026, Product Operations released version 2 of silver.product_catalog, updating product codes for a new fiscal quarter. Because the downstream reporting pipeline joined silver.core_balances b through silver.core_accounts a to silver.product_catalog p on product_code alone without temporal bounds, historical snapshots joined against future catalog versions—duplicating rows and misclassifying £8M into Investments. You must correct the join logic using effective date boundaries.
Engineering Objective
Write an SCD Type 2 effective-date temporal join query connecting core balances to the product catalog via account master data. • Complete Join Path: 1. From silver.core_balances b 2. Join silver.core_accounts a ON b.account_id = a.account_id 3. Join silver.product_catalog p ON a.product_code = p.product_code AND b.balance_date BETWEEN p.effective_from AND p.effective_to • Expected Columns: b.account_id, b.balance_date, b.ledger_balance, p.category_l1 • Filtering & Boundaries: Filter for snapshot date b.balance_date = '2026-05-31'. Enforce that balance_date falls inclusively between p.effective_from and p.effective_to. • Expected Reconciliation Result: All 3,000 Cash ISA accounts must be accurately classified under 'Savings' with £8,000,000.00 reconciled. Key Concepts: - SCD Type 2 Temporal Join: Joining facts to historical dimension states using transaction snapshot dates (BETWEEN effective_from AND effective_to) rather than system recording time. - Join Path Integrity: Traversing relational keys from balance snapshot (account_id) to account metadata (product_code) to product dimension.
Target Table: silver.core_balances b (account_id, balance_date, ledger_balance), silver.core_accounts a (account_id, product_code), silver.product_catalog p (product_code, product_name, category_l1, effective_from, effective_to)
Verification & Architecture Insights
SCD Type 2 valid-time joins ensure that when evaluating accounts as of 2026-05-31, catalog version 1 is applied (prior to the flawed May 15 release), correctly classifying Cash ISA as Savings and closing the £8m gap.