Skip to content

Role-playing dimension

A single physical dimension that one fact table references several times, each time with a different meaning. The standard case is a date dimension joined once as the order date and again as the ship date.

Also: role-playing dimensions · dimension roles

On this page · 7 sections
  1. Definition
  2. Example
  3. Why it matters
  4. Common mistakes
  5. FAQ
  6. Go deeper
  7. Related terms

A role-playing dimension is one table doing several jobs for the same fact table. An order has a date it was placed, a date it shipped, and a date it was delivered. All three are calendar dates, so all three foreign keys point to the same date dimension. Each reference is a role: the table is the same, and what it means in the query is different.

Ralph Kimball's rule is that each foreign key should join to its own view of the dimension, and that each view should rename the columns: order_month in one, ship_month in the other. Separate views keep the roles independent, so a filter on the order month does not also restrict the ship month, and the distinct names tell a report reader which date a column refers to.

Dates are the usual example and not the only one. A flight has an origin airport and a destination airport. A transfer has a sending account and a receiving account. An employee dimension can appear as both the salesperson and the approving manager on the same row. In each case the fact row holds two or more keys to one table, and a query has to say which of them it means.

create view dim_order_dates as
select
  date_key       as order_date_key,
  calendar_date  as order_date,
  calendar_month as order_month
from dim_dates;

create view dim_ship_dates as
select
  date_key       as ship_date_key,
  calendar_date  as ship_date,
  calendar_month as ship_month
from dim_dates;

select
  od.order_month,
  sd.ship_month,
  count(*) as orders
from fct_orders f
join dim_order_dates od on od.order_date_key = f.order_date_key
join dim_ship_dates sd on sd.ship_date_key = f.ship_date_key
group by od.order_month, sd.ship_month
order by od.order_month, sd.ship_month;
One physical date table plays two roles through two views. The query counts orders by the month they were placed and the month they shipped. Of the four sample orders, two were placed and shipped in January, one was placed in January and shipped in February, and one was placed and shipped in February.
Why it matters

It avoids copies. Maintaining three physical date tables, or three customer tables, means three loads that can disagree. One table with views on top has a single source, and the views add no storage.

It is also a source of wrong answers. Joining the same table twice without aliases, or filtering one role when the question was about another, returns a result that looks plausible and answers a different question.

Common mistakes
  • Joining every role to the same instance of the table in one query. A single alias forces order date and ship date to be the same row, which silently drops every order that shipped on a different day.
  • Exposing the roles with identical column names, so a report shows two columns called calendar_month and nobody can tell which is which.
  • Creating a separate physical table per role and then updating only one of them when the fiscal calendar changes.
FAQ
What is an example of a role-playing dimension?
A date dimension on an orders fact table is the standard example: the same calendar table is joined through order_date_key, ship_date_key, and delivery_date_key. Others are an airport dimension used as origin and destination, and an employee dimension used as both salesperson and manager on one row.
How do you implement a role-playing dimension in SQL?
Keep one physical table and create a view for each role, renaming the columns so each role has its own names, such as ship_date and ship_month. Then join each foreign key in the fact table to its own view. In an ad hoc query, table aliases do the same job: join dim_dates twice under two aliases.
How does Power BI handle role-playing dimensions?
A Power BI semantic model allows only one active relationship between two tables. Any further date relationships must be inactive and are used through measures written with the USERELATIONSHIP function. Microsoft's guidance describes a common alternative: load a separate date table for each role, such as Date, Ship Date, and Delivery Date, each with its own active relationship.