Slowly changing dimension

Also known as: SCD

On this page 7

A slowly changing dimension (SCD) is a dimension table whose descriptive attributes change infrequently and unpredictably, together with the set of techniques used to record those changes in a data warehouse. In Data modeling for analytical Databases, the SCD pattern decides whether a report shows facts with the attribute values that were true at the time of the event or with the values that are true today.

The concept comes from dimensional modeling, where facts such as sales or shipments are stored in a fact table and described by dimensions such as customer, product or employee. A customer moving to a new region or a product changing category is a typical change: it happens rarely compared with transactions, yet ignoring it silently distorts historical analysis.

How a slowly changing dimension preserves history

A slowly changing dimension preserves history by deciding, for each attribute, what happens when its source value changes. The load process compares incoming source rows with existing dimension rows, detects differences and then overwrites, versions or annotates the record according to the chosen technique.

The mechanism relies on the separation of two keys. The natural key (also called the business key) identifies the real-world entity, such as a customer number from the operational system. The surrogate key is a warehouse-generated integer that identifies one specific version of that entity, and fact rows reference the surrogate key, not the natural key.

Because each fact points to the version that was current when the fact was loaded, historical reports stay stable even after attributes change. The table below lists the columns that a versioned dimension typically carries.

ColumnPurposeExample value
Surrogate keyIdentifies one version of the entity48213
Natural keyLinks all versions of the same entityCUST-00917
Effective dateStart of the period when the version was valid2025-03-01
Expiration dateEnd of the validity period9999-12-31 for the current row
Current flagMarks the active version for fast filteringY or N
Row hashDetects attribute changes efficientlyChecksum of tracked columns
Typical housekeeping columns in a versioned dimension

Types of slowly changing dimensions

The types of slowly changing dimensions are numbered techniques from Type 0 to Type 7, popularized by Ralph Kimball and now standard vocabulary in data warehousing. Types 1 and 2 cover most real designs, while the others address specific reporting needs.

TypeChange handlingHistory keptTypical use
Type 0Value never changes after first loadOriginal value onlyDate of birth, original signup channel
Type 1Old value is overwrittenNoneSpelling corrections, nonanalytical attributes
Type 2New row with a new surrogate keyFull historyCustomer region, product category
Type 3Previous value stored in an extra columnOne prior valuePlanned reorganizations with before and after views
Type 4Volatile attributes moved to a history tableFull history, separatedRapidly changing attributes such as scores
Type 6Combines Types 1, 2 and 3Full history plus current valueReports needing both as-was and as-is views
Main SCD types and their behavior

Types 5 and 7 are hybrid patterns that add mini-dimensions or dual foreign keys to give fact tables both historical and current perspectives. They are less common and usually appear only in large enterprise warehouses with demanding analytical requirements.

One dimension table can mix several types at the attribute level. A customer dimension might treat the name as Type 1, the sales region as Type 2 and the loyalty tier as Type 3, which is why the decision is documented per column rather than per table.

Choosing the right SCD technique

The right SCD technique depends on the analytical question the business needs to answer. If analysts must attribute last year’s revenue to the region a customer belonged to last year, the attribute needs Type 2; if only the current value matters, Type 1 is simpler and cheaper.

The following decision table connects common requirements to a recommended type.

RequirementRecommended typeReason
Correct a data entry errorType 1The old value was never true
Report facts as they were at the timeType 2Each fact keeps its original context
Compare old and new structure side by sideType 3Both values sit in one row
Track an attribute that changes dailyType 4 or mini-dimensionAvoids explosive Type 2 row growth
Need as-was and as-is in one queryType 6Current value is copied to every version
Selecting a technique by requirement

Storage and load cost grow with history. A Type 2 dimension can multiply its row count when tracked attributes change often, so designers restrict Type 2 tracking to attributes with real analytical value and move volatile attributes elsewhere.

Implementing SCD logic in data pipelines

Implementing SCD logic means building a load step that detects changes, expires old versions and inserts new ones atomically. In SQL this is commonly done with a MERGE statement or with an update followed by an insert inside one transaction, and many ETL tools and frameworks such as dbt snapshots generate this logic automatically.

Change detection usually compares a hash of the tracked columns rather than each column individually, which keeps comparisons fast on wide tables. Fact loads then perform a point-in-time lookup, matching each fact to the dimension version whose effective and expiration dates contain the transaction date.

Late-arriving data complicates this process. When a fact arrives for a date before the current version began, the pipeline must find the version valid on that earlier date, and when a dimension change arrives late, existing facts may need to be reassigned.

Common mistakes with slowly changing dimensions

Most problems with slowly changing dimensions come from inconsistent keys and date handling. The table below lists frequent symptoms, their causes and the usual fixes.

SymptomLikely causeFix
Duplicate current rowsExpiration step failed or ran twiceEnforce one current row per natural key
Facts double countedJoin on natural key instead of surrogate keyJoin facts on the surrogate key
Gaps between versionsInconsistent date boundariesUse one inclusive or exclusive convention
History rewritten unexpectedlyAttribute configured as Type 1 by mistakeDocument and review type per column
Dimension grows too fastVolatile attribute tracked as Type 2Move it to a mini-dimension
Symptoms, causes and fixes

Understanding it simply

A slowly changing dimension is a way of keeping old records instead of erasing them when details about a customer or product change. Think of an address book where, instead of crossing out an old address, you add a new line with the date of the move.

Later, when you look at a past purchase, you can see where the customer lived at that time, not only where they live now. That simple habit keeps past reports honest and stops old numbers from shifting every time something changes.

Applied in practice

A national insurance company reorganizes its sales regions on January 1, moving about 12,000 customers from the Central region to a new Midwest region. The analytics team had modeled the customer region as a Type 2 attribute, so the nightly load expires each affected customer row with an expiration date of December 31 and inserts a new version with the Midwest region and a new surrogate key.

When finance reviews prior-year premiums, every policy sold last year still links to the Central version of the customer, so last year’s regional totals stay exactly as originally reported. Meanwhile, new policies link to the Midwest version. The team also adds a Type 6 current-region column, which lets managers restate history under the new structure in a separate view, without altering the official historical figures.