Skip to main content
So far in our data modeling journey, we have:
  1. Defined the schema of the source tables.
  2. Created a staging layer to clean and rename the columns.
  3. Created snapshots of the staging tables to track changes over time.
We shall now begin creating our dimension tables. Dimensions are descriptive attributes that provide context to facts. They are typically used for filtering and grouping data. Examples of dimensions include time, location, and product. When you track the changes to a dimension over time, it is known as a Slowly Changing Dimension.
Our dimension tables follow the following naming convention:
  • dim_<entity_name> for simple dimensions.
  • dim_<entity_name>_history for slowly changing dimensions.
You can find all the code for creating these dimension tables in the models/core/dimensions/ directory of the example-dbt-project.

Creating Dimension Tables

dim_users_history

Specification

We would like our dim_users_history table to have the following columns. Note that our user_id is no longer a primary key in this table. This is because since we can now have multiple rows for each user, each row representing a different version of the user’s history, the user_id is no longer unique. Instead, we have a dbt_scd_id column that acts as the primary key. We have also added a column called is_current that indicates whether a row is the current version of the user.

Model

The following dbt model creates a slowly changing dimension table for the users table.

dim_merchants_history

Specification

We would like our dim_merchants_history table to have the following columns:

Model

The following dbt model creates a slowly changing dimension table for the merchants table.

dim_items_history

Specification

We would like our dim_items_history table to have the following columns:

Model

The following dbt model creates a slowly changing dimension table for the items table.

dim_promotions_history

Specification

We would like our dim_promotions_history table to have the following columns: The following dbt model creates a slowly changing dimension table for the promotions table.

Next Steps

We have now created our dimension tables. In the next section, we shall create our fact tables.