📖 Scenario: You work as a data analyst in a company that processes daily sales data. The dataset grows every day, and running full data transformations every time takes a lot of time and computing resources.Your manager wants you to use incremental models in dbt to save time and reduce costs.
🎯 Goal: Build a simple incremental model in dbt that processes only new data each day instead of the entire dataset.
📋 What You'll Learn
Create a base table with daily sales data
Add a variable to track the last processed date
Write an incremental model that processes only new sales after the last processed date
Print the new_sales_data list to verify the logic
💡 Why This Matters
🌍 Real World
Companies with growing datasets use incremental models to update reports and dashboards quickly without reprocessing all data.
💼 Career
Data engineers and analysts use incremental models in dbt to optimize data pipelines, saving time and cloud computing costs.
Progress0 / 4 steps
1
Create the base sales data table
Create a variable called sales_data as a list of dictionaries with these exact entries: {'date': '2024-06-01', 'sales': 100}, {'date': '2024-06-02', 'sales': 150}, and {'date': '2024-06-03', 'sales': 200}.
dbt
Hint
Use a list of dictionaries to represent each day's sales data.
2
Add a variable for the last processed date
Create a variable called last_processed_date and set it to the string '2024-06-01'.
dbt
Hint
This variable will help filter new data to process.
3
Write the incremental model logic
Create a list called new_sales_data that contains only the entries from sales_data where the 'date' is greater than last_processed_date.
dbt
Hint
Use a list comprehension to select only new entries.
4
Print the new incremental data
Write a print statement to display the new_sales_data list.
dbt
Hint
The output should show only the sales data after 2024-06-01.
Practice
(1/5)
1. What is the main reason incremental models save time and cost in dbt?
easy
A. They skip data validation steps to speed up execution.
B. They run all transformations in parallel automatically.
C. They use less memory by compressing data during processing.
D. They process only new or changed data instead of the entire dataset.
Solution
Step 1: Understand incremental model behavior
Incremental models update only the new or changed data instead of reprocessing everything.
Step 2: Connect behavior to time and cost savings
Processing less data means less compute time and lower cloud costs.
Final Answer:
They process only new or changed data instead of the entire dataset. -> Option D
Quick Check:
Incremental = process new data only [OK]
Hint: Incremental means update only new or changed data [OK]
Common Mistakes:
Thinking incremental models reprocess all data
Confusing incremental with parallel processing
Assuming incremental skips validation
2. Which dbt function is used inside an incremental model to filter only new or changed data?
easy
A. is_incremental()
B. filter_new()
C. increment_only()
D. new_data_check()
Solution
Step 1: Recall dbt incremental syntax
dbt provides the function is_incremental() to detect incremental runs.
Step 2: Identify correct function for filtering
This function is used in the WHERE clause to filter new or changed data during incremental runs.
Final Answer:
is_incremental() -> Option A
Quick Check:
Use is_incremental() to filter incremental data [OK]
Hint: Use is_incremental() to filter new data in incremental models [OK]
Common Mistakes:
Using non-existent functions like filter_new()
Confusing function names with similar words
Not using any function to filter incremental data
3. Given this dbt incremental model snippet, what rows will be processed during an incremental run?
select * from source_table
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}
medium
A. All rows from source_table every time
B. Only rows with updated_at newer than the max in the target table
C. Only rows with updated_at older than the max in the target table
D. No rows are processed during incremental runs
Solution
Step 1: Analyze the WHERE clause inside is_incremental()
The condition filters rows where updated_at is greater than the max updated_at in the target table.
Step 2: Understand incremental run behavior
During incremental runs, only new or updated rows with newer timestamps are processed.
Final Answer:
Only rows with updated_at newer than the max in the target table -> Option B
Quick Check:
Incremental filters rows newer than max timestamp [OK]
Hint: Check updated_at > max(updated_at) for incremental rows [OK]
Common Mistakes:
Thinking all rows are processed every time
Confusing greater than with less than in filter
Assuming no rows processed during incremental
4. This incremental model code has an error. What is the problem?
select * from source_table
{% if is_incremental() %}
where updated_at < (select max(updated_at) from {{ this }})
{% endif %}
medium
A. The filter uses < instead of >, so it excludes new data.
B. The is_incremental() function is misspelled.
C. The model is missing a primary key declaration.
D. The select statement is missing a GROUP BY clause.
Solution
Step 1: Check the filter condition logic
The condition uses < (less than) which filters older rows, not new or changed ones.
Step 2: Understand incremental filtering needs
Incremental models must filter rows newer than the max timestamp to add new data.
Final Answer:
The filter uses < instead of >, so it excludes new data. -> Option A
Quick Check:
Incremental filter must use > for new data [OK]
Hint: Use > in incremental filter to include new data [OK]
Common Mistakes:
Using less than instead of greater than in filter
Ignoring is_incremental() spelling
Thinking primary key or GROUP BY is required here
5. You have a large sales table updated daily. You want to build a dbt incremental model that only adds new sales since the last run. Which approach best saves time and cost?
hard
A. Use an incremental model but do not filter any rows inside is_incremental() block.
B. Use a full-refresh model that rebuilds the entire sales table every run.
C. Use an incremental model with is_incremental() filtering rows where sale_date > max(sale_date) in the target table.
D. Use a model that only selects sales from the current day without checking previous data.
Solution
Step 1: Identify incremental model best practice
Filtering new rows using is_incremental() with a condition on sale_date ensures only new data is processed.
Step 2: Compare other options
Full-refresh rebuilds all data (slow, costly). No filtering processes all data each run. Selecting only current day misses data if runs are delayed.
Final Answer:
Use an incremental model with is_incremental() filtering rows where sale_date > max(sale_date) in the target table. -> Option C
Quick Check:
Filter new data with is_incremental() for efficiency [OK]
Hint: Filter new rows with is_incremental() and max date check [OK]
Common Mistakes:
Choosing full-refresh for large tables
Not filtering rows in incremental runs
Selecting only current day without history check
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.