Sub topic 11
Choosing the right approach for your model
This chapter assumes you know star schemas, one-to-many relationships, simple DAX measures, and how CALCULATE changes filter context. Earlier chapters showed three ways to report on a second date role such as ship date. Here you compare them and pick one for a given model.
The three approaches
All three start from a fact table with several date columns. In the examples, Sales[OrderDate] has the active relationship to 'Date'[Date], and Sales[ShipDate] has an inactive one.
- USERELATIONSHIP in a measure. You keep one Date table and write a measure that activates the inactive relationship for that calculation only.
- A duplicated Date table. You create a second table, such as
Ship Date = 'Date', and give it its own active relationship toSales[ShipDate]. - A calculation group. You add a calculation item that wraps
SELECTEDMEASURE ()inUSERELATIONSHIP, so users can switch the date role for any measure.
Sales Amount by Ship Date =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)How they differ
| Question | USERELATIONSHIP measure | Duplicated Date table | Calculation group |
|---|---|---|---|
| Where is the role chosen? | Inside each measure | By which Date table the user filters | By a slicer on the calculation item |
| Extra measures needed | One per measure and role | None | None |
| Extra tables in the model | None | One per role | One calculation group |
| Order and ship dates on one visual | Possible only with separate measures | Easy, each table gets its own axis or slicer | Awkward, one role is active at a time |
| Filtering orders by order date and ship date together | Hard | Easy | Hard |
| Tooling | Power BI Desktop | Power BI Desktop | Tabular Editor or the calculation group designer |
Decision criteria
Use these questions in order.
- Do users need to filter on two roles at the same time? An example is "orders placed in March that shipped in April". A single Date table cannot hold two filters on the same column for different roles. Use a duplicated Date table for each role.
- Do you have many measures that need a ship-date version? If you would write the same wrapper around ten or twenty measures, a calculation group avoids the repetition. It also keeps time intelligence consistent.
- Are there only a few ship-date measures? Use USERELATIONSHIP. It adds no tables, keeps the model small, and the logic is visible in the measure.
Shipped Sales YTD =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
DATESYTD ( 'Date'[Date] )
)The diagram shows the same questions as a flow.
Trade-offs to weigh
- Model size and clarity. Each duplicated Date table adds a table to the field list. Users must pick the right one, so name them clearly, for example
Order DateandShip Date. Hide the columns you do not want them to use. - Maintenance. A calculation group changes how every measure behaves when its item is selected. If a measure should ignore the date role, such as a count of customers, test it with the item active.
- Skills and tooling. Calculation groups need Tabular Editor or the model view's calculation group feature. A team without that tooling may prefer the other two approaches.
- Time intelligence. Functions such as
DATESYTDwork with any of the three, but they must run on the Date table that is actually filtering the fact table. With a duplicated table, use that table's date column in the function.
Combining approaches
The approaches are not exclusive. A common pattern is to duplicate the Date table for the roles that need slicers, and keep USERELATIONSHIP for one rarely used role such as due date. Choose by what users do in reports, then keep the pattern consistent so that other developers can predict how a new measure should be written.
Exercise
A report must show a matrix of orders placed in each month (rows) against the month they shipped (columns). Which approach fits, and why does a USERELATIONSHIP measure not fit?
Show answer
Use a duplicated Date table for the ship date, with an active relationship to Sales[ShipDate], and keep the original Date table for the order date. The matrix needs both roles filtering the same fact rows at once. A USERELATIONSHIP measure makes ship date the active role for that calculation, so the order-date table can no longer filter in the same measure.
Exercise
Your model has 25 measures, and business users want any of them viewed by order date or by ship date using a slicer. Which approach reduces the work most?
Show answer
A calculation group with a "Ship Date" item that wraps SELECTEDMEASURE () in USERELATIONSHIP, plus an "Order Date" item with no change. You write the logic once instead of creating 25 ship-date measures.