Module 4 of 16

Staging Models

Clean source data gently: rename, cast, standardize, and expose a stable base layer.

Updated

100 minutes1 exercisesFree

Start here

Learning objectives

  • Build staging models that stay close to the source
  • Apply safe renaming and type casting
  • Avoid burying business logic too early
Staging Models Follow the arrows. Each box is one idea you will practice in this module. Raw step 1 Rename step 2 Cast step 3 Clean step 4 Stage step 5 Production analytics engineering turns raw records into governed, trusted business meaning.

The Mental Model

Staging models are the clean mirror of raw sources. They should make data easier to use without making heavy business decisions.

A staging model is like rewriting messy notes into clean handwriting. You are not changing the story yet; you are making it readable.

Dataset reference: ecommerce tables and grain assumptions.

Standardize values without changing grain

A source sends padded status strings and amounts in cents. Normalize those representations while retaining one row per source order.

with raw_orders(order_id, amount_cents, status) as (
  values (101, 1250, ' PAID '), (102, 0, 'CANCELLED')
)
select order_id,
       amount_cents / 100.0 as amount,
       lower(trim(status)) as status
from raw_orders;

Expected rows: (101, 12.5, paid) and (102, 0.0, cancelled). The cancelled order remains present: deciding which states count as revenue belongs in a documented business model. Validate source types before casting and record the currency separately; a numeric conversion does not perform foreign-exchange conversion.

Interactive Check

Question: Should a staging model calculate lifetime customer value?

Reveal the answer

No. That is business logic across many events and belongs later. Staging should focus on source cleanup: names, types, null handling, and basic standardization.

Practice: Fix stg_orders

Turn a messy raw_orders table into a clean staging model.

Use the guided lab below to record your result, assumptions, and the check that would catch an incorrect result.

Production notes

Keep these close

  • Use one staging model per source table. It gives every raw table one official cleaned interface.

Common mistakes

What usually breaks

  • Joining multiple sources in staging
  • Adding metrics to staging models
  • Leaving cryptic source column names unchanged

Key terms

Vocabulary used in this module

Staging model

A dbt model that cleans and standardizes one raw source table.

Source

An upstream table that dbt reads but does not create.

Exercises

Practice inside the lesson

30-45 minutesBeginner

Fix stg_orders

Turn a messy raw_orders table into a clean staging model.

  1. Rename id to order_id
  2. Cast created_at to a timestamp
  3. Standardize status values to lowercase
  4. Keep source-level fields only
  5. Write the model grain in one sentence

Expected evidence

A short answer, SQL/YAML snippet, or lineage map that can live directly in the course page notes.

Recap

Key takeaways

  • Staging models are stable cleaned source interfaces
  • Keep business logic out of staging unless it is source-specific cleanup
  • Good staging makes every downstream model simpler

Related resources

Keep learning across CodersSecret