Using Jinja for loops on repeated SQL 1
Scanning through your customers.sql
file again, you realize that there is a lot of repeating of CASE WHEN ...
statements for creating different columns counting orders by status. This is causing the data mart model to be super long and complex.
As an initial step, you broke out that CTE into its own intermediary mart model called int_customers__pivoted.sql
and moved the logic there.
However, the more you look at it, the more it feels like the intermediate model can benefit from a Jinja loop, for better scalability and less repeating.
This exercise is part of the course
Case Study: Building E-Commerce Data Models with dbt
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
