0
0
dbtdata~5 mins

dbt-utils (surrogate_key, pivot, unpivot) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the surrogate_key macro in dbt-utils do?
The surrogate_key macro creates a unique key by combining one or more columns. It helps identify each row uniquely, like a fingerprint for data records.
Click to reveal answer
beginner
How does the pivot macro in dbt-utils transform data?
The pivot macro turns rows into columns. It reshapes data so that unique values from one column become new columns, making data easier to compare side by side.
Click to reveal answer
beginner
What is the purpose of the unpivot macro in dbt-utils?
The unpivot macro does the opposite of pivot. It turns columns back into rows, which helps when you want to analyze data in a long, tidy format.
Click to reveal answer
intermediate
Why is using a surrogate key useful in data modeling?
Surrogate keys provide a simple, consistent way to identify rows uniquely, even if natural keys change or are missing. This helps keep data clean and relationships clear.
Click to reveal answer
intermediate
When would you use pivot and unpivot in your data transformations?
Use pivot to create wide tables for easier comparison across categories. Use unpivot to create long tables for easier filtering and aggregation.
Click to reveal answer
What does the surrogate_key macro generate in dbt-utils?
AA visualization of data
BA unique identifier combining columns
CA new table with aggregated data
DA summary statistic of a column
Which macro would you use to turn multiple rows into columns?
Apivot
Bsurrogate_key
Cunpivot
Djoin
What is the main use of the unpivot macro?
ATo turn columns into rows
BTo combine columns into a single unique key
CTo filter data by a condition
DTo create a new table
Why might surrogate keys be preferred over natural keys?
AThey are easier to read
BThey reduce the size of the data
CThey automatically create indexes
DThey never change and are always unique
If you want to analyze data by categories side by side, which macro helps?
Asurrogate_key
Bunpivot
Cpivot
Dfilter
Explain how the surrogate_key macro works and why it is useful in data modeling.
Think about how you give each row a unique ID.
You got /3 concepts.
    Describe the difference between pivot and unpivot macros and when to use each.
    Consider how you reshape data for different analysis needs.
    You got /3 concepts.