In this lesson, you will learn how to use a single "Date" dimension to support multiple business roles within your fact tables simultaneously.
The Problem: Multiple Dates, One Calendar
Imagine you have an Orders fact table. Each record needs to track an order_date, a ship_date, and a delivery_date. If you create three separate date tables, you will bloat your database and make complex cross-date reporting (like calculating the time between shipping and delivery) nearly impossible to maintain.
The Solution: Role-Playing Dimensions
A role-playing dimension is a single physical DimDate table that serves multiple logical purposes. In your fact table, you include multiple foreign keys that all point back to the primary key of this same DimDate table.
For example, your FactOrders table might look like this:
CREATE TABLE FactOrders (
order_id INT PRIMARY KEY,
order_date_key INT, -- References DimDate(date_key)
ship_date_key INT, -- References DimDate(date_key)
delivery_date_key INT, -- References DimDate(date_key)
order_amount DECIMAL(10,2),
FOREIGN KEY (order_date_key) REFERENCES DimDate(date_key),
FOREIGN KEY (ship_date_key) REFERENCES DimDate(date_key),
FOREIGN KEY (delivery_date_key) REFERENCES DimDate(date_key)
);
How It Works in Practice
When your BI tool queries the data, it treats each foreign key as a different "view" or "role" of the dimension.
If a user wants to see "Total Sales by Month" based on when they were ordered, the engine joins FactOrders to DimDate using the order_date_key. If they want to see "Total Sales by Month" based on when they were shipped, the engine performs the same join, but uses the ship_date_key instead.
Because both roles share the same underlying DimDate table, you only need to build and maintain one calendar. This keeps your schema clean, consistent, and easy to query for time-based calculations without needing redundant tables.
Key Takeaway: Use a single, shared date dimension with multiple foreign keys in your fact table to represent different temporal roles without duplicating your calendar data.