Sub topic 1
One Date table, several roles: order, ship, and due dates
Prerequisites
This chapter assumes you can do the following:
- You know star schema terms: fact table, dimension table, and one-to-many relationship.
- You can write simple DAX measures such as
SUM. - You have a basic idea of what filter context is.
You do not need to know CALCULATE in detail yet. Later chapters cover it.
What a role-playing dimension is
A sales fact table often holds more than one date. A single order row can carry an order date, a ship date, and a due date. Each of these answers a different business question.
All three columns describe a point in time, so all three can use the same Date dimension. The Date table has one row per calendar day, with columns such as year, month, and weekday. It is the same table each time. Only the meaning of the link changes.
A dimension used in several distinct ways by one fact table is a role-playing dimension. Here, the Date table plays three roles: order date, ship date, and due date.
The alternative would be to build three copies of the Date table by hand. That works, but it makes the model larger and harder to maintain. Later chapters compare that approach with the one this tutorial focuses on.
The example model
The rest of this tutorial uses a model with two tables.
| Table | Key columns | Role |
|---|---|---|
| Sales (fact) | OrderDate, ShipDate, DueDate, SalesAmount | One row per order line |
| Date (dimension) | Date, Year, Month, Weekday | One row per calendar day |
Sales has three date columns. Each one can relate to 'Date'[Date] in a one-to-many relationship, with Date on the one side and Sales on the many side.
-- The Sales table in this tutorial has these columns:
-- Sales[OrderDate] date
-- Sales[ShipDate] date
-- Sales[DueDate] date
-- Sales[SalesAmount] decimal numberThe block above is a comment-only sketch of the columns. It is not a measure to run.
Seeing the roles in the model
The diagram shows one Date table linked to three columns in the fact table. In Power BI Desktop's model view, you see the same picture as three lines between the two tables.
Each line is a separate relationship. Each one means something different:
- Date to OrderDate: a date filter selects the orders placed on that day.
- Date to ShipDate: a date filter selects the orders shipped on that day.
- Date to DueDate: a date filter selects the orders due on that day.
Why the roles matter for reports
Suppose a user puts 'Date'[Year] on a chart axis next to a sales total. The model must decide which of the three date columns the year should filter. It cannot filter by all three at once. If it did, a row would count only when its order, ship, and due dates all fell in the same year. That is almost never what anyone wants.
So the model needs a rule that picks one role by default. The next chapters explain that rule, and how to use the other roles when you need them.
How to recognize a role-playing dimension
Look for these signs in your own model:
- The fact table has several columns of the same kind, such as multiple dates.
- Each column has its own business meaning, like order, ship, or due.
- Each column is meant to be filtered by the same dimension.
Dates are the most common case. Other examples include a Customer table used as both "bill-to" and "ship-to", or an Airport table used as both "origin" and "destination" for flights.
Common mistake at this stage
A frequent error is to assume that a report filtered by year is filtered by every date column. It is not. Only one relationship filters the fact table, and which one that is depends on how the model is set up. If you do not know which role your visuals use, you can report order-date numbers under a ship-date label.
Exercise
A Sales table has OrderDate, ShipDate, and ReturnDate columns, all linked to one Date table. Is Date a role-playing dimension? Name its roles.
Show answer
Yes. One Date table is used in three distinct ways by the same fact table. Its roles are order date, ship date, and return date.
Exercise
A Flights fact table has OriginAirport and DestinationAirport columns, both linked to an Airport table. Is this a role-playing dimension, and why?
Show answer
Yes. The Airport table plays two roles, origin and destination, for the same fact table. The pattern is the same as with dates.