How to incrementally load a fact table with dbt in Microsoft Fabric

The DBT (data build tool) logo.
Comments 0

Share to social media

TL;DR: An incremental load in dbt processes only new or changed rows instead of rebuilding the whole table. To load a fact table incrementally in Microsoft Fabric, set the model’s materialization to incremental, filter with the is_incremental() macro, and define a unique key and the delete+insert strategy to avoid duplicates.

This guide starts with a simple full load (the truncate-and-load pattern) using the AdventureWorksLT sales data, then converts it to an incremental model and tests it in the dbt debug logs.

Previously, I’ve covered how to create type 2 slowly changing dimensions, how to load regular dimensions with macros, and how to create a date dimension. The code runs in dbt Cloud against a Microsoft Fabric Warehouse.

How to load a fact table with dbt

First, I’ll explain how to load a fact table with dbt. There are various methods for achieving this.

Full load: the truncate-and-load pattern in dbt

The simplest way of loading a fact table is either dropping the table or truncating it, and then loading all data from scratch.

It may not be the most efficient way to load data, but development time is short, there’s not much that can go wrong (when compared with incremental loading techniques), and modern data warehouses can process millions of rows with ease.

In dbt, when you materialize a model as a table and don’t specify any loading technique, the default is a full reload. dbt drops the existing table and creates a new one with a CREATE TABLE AS SELECT statement, so it’s technically drop-and-recreate rather than TRUNCATE.

In reality, a lot more happens than that. To see exactly how dbt loads data, you can always open the debug logs:

An image showing the dbt debug logs.
The debug logs in dbt.

Thus, to load a fact table from scratch, we need to define a model that contains the business logic (any calculations for measures and lookups to the relevant dimensions).

Helpfully, I’ve already written one, as shown in my Loading Models from Source Data with dbt guide:

Since we’ve created a customer and product dimension by now, we need to retrieve their respective surrogate keys. There are two ways of achieving this.

The lookup method: join to the dimension for surrogate keys

We can do a lookup on the actual dimension with a LEFT OUTER JOIN on the business key and fetch the surrogate key (SK). The advantage here is that we can check for referential integrity. If the SK isn’t found, we can replace it with a dummy value (like -1, for example), or maybe even throw an error.

The hash method: generate surrogate keys without a join

Alternatively, we can hash the business key of the dimension (ProductID, for example) by using the same method we used to create the surrogate keys of the dimension.

This has the advantage of not needing the LEFT OUTER JOIN, and we can load the fact table in parallel with the dimensions.

However, there’s no check on referential integrity, and there’s no lineage that dbt can use.

Let’s alter the script to use the first option – the lookup method:

Image showing the script run with the lookup method.
The lookup method.

Every time we run the model in dbt, the FactSales table will be emptied, and all the data from the source tables will be loaded into the fact table.

How to load a fact table incrementally in dbt (in brief)

  1. Convert the full-load model to a view (for example, vw_FactSales) and add an UpdateDate column to simulate changing data.

  2. Create a new model, FactSales, that selects every column from the view and sets materialized = 'incremental'.

  3. Add an {% if is_incremental() %} block that filters on UpdateDate greater than the maximum value already in {{ this }}.

  4. Set unique_key to ['SalesOrderID','SalesOrderDetailID'] and incremental_strategy to 'delete+insert'.

  5. Run the model twice and check the row counts and debug logs to confirm no duplicates.

How to load a fact table incrementally in dbt (in more detail)

Loading all the data every time we run the dbt model might not be the most efficient way to deal with compute resources, especially in cloud environments, for example, where we’re billed by the compute resources spent.

If the fact table becomes too large, or if it takes too long to run the model, we’ll want to change to an incremental load.

When loading incrementally, we only deal with data that has been changed, added or deleted since the last time we’ve run the ETL (extract, transform, load). This is much more efficient but takes more development time, and may be harder to debug if something goes wrong.

In dbt, we can configure a model to be loaded incrementally by using the incremental materialization:

When we want to load an incremental table, there are two options.

Subscribe to the Simple Talk newsletter

All the latest articles, guides, podcasts, and more – delivered straight to your inbox.
Subscribe now

Initial (full) load vs incremental load

An initial load is a full load where all the data that we currently have is copied into the table.

Ideally, we only need to do this once (when the table is loaded for the first time), but we might want to occasionally do a full load if we have all the source data available.

For example, the column that detects changes cannot be 100% trusted, so on weekends we may want to load all the data to make sure it has all been transferred correctly.

Or, maybe something went wrong with the ETL, data is missing, and we want to transfer all data again to start ‘fresh’.

How to force a full load of an incremental model

To force a full load of an incremental model, run it with the --full-refresh flag (for example, dbt run --full-refresh --select FactSales) or set full_refresh = true in the model config.

dbt then rebuilds the table from scratch, and is_incremental() returns false for that run.

How to filter new rows with the is_incremental() macro

An incremental load transfers only the changes since the last ETL run, or loads a moving fixed window of data (for example, everything from the last three days).

This means we need to optionally add a WHERE clause to our model. No filters are required when doing a full load but, when loading incrementally, we must filter on one (or more) columns to determine the change set.

This is where the is_incremental() macro comes into play. With this macro, we can dynamically add logic to our model that will handle the incremental loading.

Let’s illustrate this with our FactSales model.

Step-by-step guide

First, we convert the existing model to a view, and then rename the model to vw_FactSales.sql – just like we did with the product and customer dimensions:

An image showing the renaming of the model.
Renaming the model.

At the end of the view, we add an UpdateDate column using GETDATE():

an image showing the addition of an UpdateDate column using GETDATE().
Adding an UpdateDate column.

Every time data is selected from the view, this column will change values so we can ‘mock’ that data has changed.

Next, we add a new model and name it FactSales.sql. This model will hold our incremental loading strategy and will select every column from the view:

Now, we can add the is_incremental() macro to this model:

What happens if is_incremental() returns true

If is_incremental() returns true, the WHERE clause will be added to the model, and only the most recent data since the last ETL run will be added.

The {{ this }} object refers to the current model – in other words, the FactSales table.

Using this allows us to query the model we’re loading, so we can use this to find the maximum UpdateDate. Only more recent data should be loaded into the model.

What happens if is_incremental() returns false

If is_incremental() returns false, nothing is added to the SELECT statement, and all data from the view will be loaded into the fact table.

This function will return true if:

  • The model is configured as incremental
  • The table already exists in the database (if it doesn’t, we will do an initial load)
  • There’s no “full” load set (which can be done as a config or as a command).

When we compile our model, note that there’s no WHERE clause added. This is because the table doesn’t yet exist in the Fabric warehouse:

an image showing that the table doesn't yet exist in the fabric warehouse, hence there's no visible WHERE clause.
The table doesn’t yet exist in the Fabric warehouse, so there’s no WHERE clause…

When we run the models for the view and the fact table, then compile again, the WHERE clause is added:

an image showing that the WHERE clause has now been added
The WHERE clause is now visible.

If we run the model again, all data will be loaded into the fact table for a second time, since the UpdateDate column now has a more recent value:

an image showing that the UpdateDate column now has a more recent value.
The UpdateDate column now has a more recent value.

However, what if the data contains both inserts and updates? Or, what if we load the same data in an ETL that runs later on? And how do we handle this to avoid duplicates in our fact table?

dbt incremental strategies: append, delete+insert, merge, and more

The key to loading an incremental table correctly is to specify a unique key and an incremental strategy.

Depending on the strategy used, dbt can use the unique key to determine if an incoming row should be used for an update or an insert.

The following strategies are available:

The append strategy

With the append strategy, data returned by the SELECT statement of the model is inserted ‘as-is’ into the model without checks. If no unique key is specified, this is the default behavior. It explains why we ended up with 1,084 rows in the fact table: the 542 source rows were loaded twice.

This strategy might be useful when your fact table is insert-only and you have a solid method of detecting new rows in your source (event stream data, for example).

The delete+insert strategy

If the unique key gives a match, the row is deleted from the target table and the row from the source is inserted instead. You can use the delete+insert if you use a moving batch window (e.g. all data from the last 3 days).

If data already exists, however, it’s simply deleted and re-inserted.

The merge strategy

The merge strategy ensures that, if an incoming row doesn’t exist, it is inserted. Additionally, if the unique key gives a match, the target row will be updated. And finally, if a unique key is not specified, the merge reverts to append.

The insert_overwrite strategy

insert_overwrite can be used on partitioned tables, where an entire partition is overwritten if it already exists. If the partition does not currently exist, however, data is written to a new partition.

The microbatch strategy

The microbatch strategy is used for processing large time-series datasets. It supports parallel batch execution.

Which incremental strategies does dbt support in Microsoft Fabric?

It’s very important to understand that not every database adapter supports all strategies.

For our case, Microsoft Fabric supports append, merge, delete+insert, and microbatch.

Among them, delete+insert seems the most logical choice for our case, given we don’t need to update fact rows.

The columns SalesOrderID and SalesOrderDetailID uniquely define a row. The config of the model becomes:

The dbt incremental strategies in summary (comparison guide)

StrategyWhen the unique key matchesBest forSupported in Fabric?
appendNothing is checked; rows are inserted as-is (the default without a unique key)Insert-only data with reliable new-row detection, such as event streamsYes
delete+insertThe matching target row is deleted and the source row insertedMoving batch windows; fact tables that don’t need updatesYes
mergeThe target row is updated; new rows are insertedSources with both inserts and updatesYes
insert_overwriteThe whole partition is overwrittenPartitioned tablesNo
microbatchNot applicable; data is processed in time-based batches, in parallelVery large time-series datasetsYes

How to test the incremental model (check for duplicates in the logs)

First, let’s drop the table again so we can start fresh. The first time we run the model, 542 rows will be inserted into the fact table. Then, when run a second time, dbt will use the unique key to determine if a row already exists or not.

Since all rows already exist, 542 rows will be deleted, and the same data will be inserted again.

an image showing 542 rows being deleted.
542 rows are deleted…

When we dive into the debug logs, we can find the DELETE statement run by the incremental strategy:

an image showing the DELETE statement run by the incremental strategy.
The DELETE statement run by the incremental strategy.

After the DELETE, INSERT, and SELECT statements are executed:

Image showing the result of after the DELETE, INSERT, and SELECT statements are executed.
After the DELETE, INSERT, and SELECT statements are executed.

Both statements ensure we don’t end up with duplicate rows in our fact table.

Conclusion: when to use incremental loads in dbt

Incremental loading lets dbt update a fact table with only new or changed rows instead of rebuilding it every run.

In this article, we started with a full load, then converted the model to materialized = 'incremental', filtered with is_incremental(), and set a unique key with the delete+insert strategy so reruns don’t create duplicates.

The changes to the model were small; dbt does the heavy lifting.

Incremental materialization also works for other table types. Delete+insert, for example, suits an incremental SCD Type 1 dimension. For more advanced options, see the dbt incremental models documentation.

Simple Talk is brought to you by Redgate Software

Take control of your databases with the trusted Database DevOps solutions provider. Automate with confidence, scale securely, and unlock growth through AI.
Discover how Redgate can help you

FAQs

1. What is an incremental model in dbt?

An incremental model is built in full on its first run, then updated with only new or changed rows on later runs. You enable it with materialized = 'incremental' and filter the source data with the is_incremental() macro. This reduces compute time and cost on large tables.

2. What does is_incremental() do in dbt?

is_incremental() returns true when the model is configured as incremental, the target table already exists, and no full refresh has been requested. When it’s true, dbt adds the code inside the {% if is_incremental() %} block, typically a WHERE filter on a timestamp, so only recent data is loaded.

3. Which incremental strategies does dbt support in Microsoft Fabric?

The dbt Fabric adapter supports append, merge, delete+insert and microbatch. For insert-only fact tables, delete+insert is usually the best fit. dbt uses the unique key to delete matching rows, then inserts the incoming rows, so no duplicates are created.

4. Why does my dbt incremental model create duplicate rows?

Duplicates usually appear because no unique_key is set, so dbt defaults to the append strategy and inserts every row it selects. Define a unique key (for a sales fact, SalesOrderID and SalesOrderDetailID) and use delete+insert or merge so existing rows are replaced, not repeated.

5. How do I force a full reload of an incremental model?

Run the model with the --full-refresh flag, for example dbt run --full-refresh --select FactSales, or set full_refresh = true in the model config. dbt then rebuilds the table from scratch, and is_incremental() returns false for that run.

The last answer depends on the article naming --full-refresh, which it doesn’t do yet. Add one sentence to the “Initial load” section so the FAQ is backed by the body.

This document contains proprietary information and is protected by copyright law.

Copyright © 2026 Red Gate Software Limited. All rights reserved

Article tags

About the author

Koen Verbeeck

See Profile

Koen Verbeeck is a data professional working at AE. He helps organizations to get insight in their data and to improve their analytics solutions. Koen has over a decade of experience in developing data warehouses, models and reports using the Microsoft data platform. Koen was a Microsoft Data Platform MVP for 8 years. He has a blog at http://www.sqlkover.com, writes articles for MSSQLTips.com and is a frequent speaker at Microsoft Data Platform events.

Koen's contributions