Year-to-date by ship date with USERELATIONSHIP
Run a year-to-date total on the ship date instead of the order date by switching on the inactive relationship inside CALCULATE.
You will learn to
- Combine a time-intelligence measure with USERELATIONSHIP
- Explain which date a YTD measure follows
- Explain why order-date and ship-date YTD differ around New Year
How it works
Every sale has two dates: `Sales[DateKey]` (ordered) and `Sales[ShipDateKey]` (shipped). Both relate to the one `'Date'` table, but only the order-date relationship is **active**. That is why `[Sales YTD]` follows order dates.
`USERELATIONSHIP(Sales[ShipDateKey], 'Date'[DateKey])` switches the ship-date relationship on for the duration of a calculation. It only works as a **filter argument of CALCULATE** (or of functions built on it, such as TOTALYTD’s optional third argument).
Time intelligence stacks with it. The Date table still decides which days count as “year to date”; USERELATIONSHIP decides which sales those days pick up. Orders placed in late December and shipped in January move into the new year.
Practice it hands-on with a real data model and a live report that updates as you type.
Quantity YTD by Ship Date = CALCULATE(TOTALYTD([Total Quantity], 'Date'[Date]), USERELATIONSHIP(Sales[ShipDateKey], 'Date'[DateKey]))