Bird
0
0

You have a sales table with columns: region, product, jan, feb, mar. You want to transform monthly sales columns into rows with columns month and sales. Which dbt-utils macro and usage is correct?

hard📝 Application Q8 of 15
dbt - Packages and Reusability
You have a sales table with columns: region, product, jan, feb, mar. You want to transform monthly sales columns into rows with columns month and sales. Which dbt-utils macro and usage is correct?
A{{ dbt_utils.unpivot(relation=ref('sales'), columns=['jan', 'feb', 'mar'], name_column='month', value_column='sales') }}
B{{ dbt_utils.pivot(relation=ref('sales'), column='month', value='sales') }}
C{{ dbt_utils.surrogate_key(['region', 'product']) }}
D{{ dbt_utils.aggregate(['jan', 'feb', 'mar']) }}
Step-by-Step Solution
Solution:
  1. Step 1: Identify transformation goal

    Converting columns jan, feb, mar into rows is unpivoting.
  2. Step 2: Match macro usage

    unpivot macro with columns list and name/value columns matches the goal.
  3. Final Answer:

    {{ dbt_utils.unpivot(relation=ref('sales'), columns=['jan', 'feb', 'mar'], name_column='month', value_column='sales') }} -> Option A
  4. Quick Check:

    unpivot converts columns to rows [OK]
Quick Trick: Use unpivot to turn multiple columns into rows [OK]
Common Mistakes:
MISTAKES
  • Using pivot instead of unpivot
  • Confusing surrogate_key with reshaping macros
  • Assuming aggregate macro exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes