Bird
0
0

Which approach best applies the multi-source fan-in pattern?

hard🚀 Application Q8 of 15
dbt - Advanced Patterns

You have three dbt source models: orders, refunds, and customers. You want to build a fan-in model that reports total net sales per customer. Which approach best applies the multi-source fan-in pattern?

ACreate separate models for each source and union them without joins.
BJoin <code>orders</code> and <code>refunds</code> on <code>order_id</code>, aggregate net sales, then join with <code>customers</code> on <code>customer_id</code>.
CJoin <code>customers</code> directly with <code>orders</code> only, ignoring refunds.
DUse a CROSS JOIN between all three sources to combine all rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    We want net sales per customer, which requires combining orders and refunds.
  2. Step 2: Apply multi-source fan-in

    First join orders and refunds on order_id to calculate net sales, then join with customers on customer_id to attribute sales.
  3. Final Answer:

    Join orders and refunds on order_id, aggregate net sales, then join with customers on customer_id. -> Option B
  4. Quick Check:

    Aggregate related sources before joining to customers [OK]
Quick Trick: Aggregate related sources before joining customers [OK]
Common Mistakes:
MISTAKES
  • Ignoring refunds when calculating net sales
  • Using CROSS JOIN causing data explosion
  • Unioning sources without joining on keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes