Bird
0
0

This dbt model uses pivot macro:

medium📝 Debug Q7 of 15
dbt - Packages and Reusability
This dbt model uses pivot macro:
{{ dbt_utils.pivot(
  relation=ref('orders'),
  column='status',
  value='amount'
) }}

The query fails with an error about missing aggregate. What is the fix?
AChange pivot to unpivot macro
BRemove the value parameter
CAdd an aggregate parameter like 'sum' to the pivot macro
DPass columns as a list instead of string
Step-by-Step Solution
Solution:
  1. Step 1: Understand pivot macro requirements

    Pivot macro requires an aggregate function when multiple rows per pivot column exist.
  2. Step 2: Fix missing aggregate error

    Adding aggregate='sum' or another aggregate resolves the error.
  3. Final Answer:

    Add an aggregate parameter like 'sum' to the pivot macro -> Option C
  4. Quick Check:

    pivot needs aggregate when values can repeat [OK]
Quick Trick: Always specify aggregate in pivot if duplicates exist [OK]
Common Mistakes:
MISTAKES
  • Ignoring aggregate parameter
  • Confusing pivot with unpivot
  • Passing columns incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes