Sub topic 7
Year-to-date and other time intelligence by ship date
This chapter assumes you have a model with Sales related to 'Date' through an active Sales[OrderDate] relationship and an inactive Sales[ShipDate] relationship. It also assumes you can write a CALCULATE measure. Here you apply time intelligence functions to the ship-date role.
Why time intelligence follows the relationship
Time intelligence functions such as DATESYTD and SAMEPERIODLASTYEAR do not look at the fact table. They return a set of dates from the Date table, and CALCULATE applies that set as a filter. The filter then travels to Sales through whichever relationship is active during that CALCULATE.
USERELATIONSHIP changes which relationship that is. If you put it in the same CALCULATE, the date set flows through Sales[ShipDate] instead of Sales[OrderDate].
Year-to-date by ship date
Start from the base measure and the ship-date version.
Sales Amount = SUM ( Sales[SalesAmount] )
Shipped Sales YTD =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
DATESYTD ( 'Date'[Date] )
)Place 'Date'[Month] on rows of a matrix. Each month shows the sales shipped from January through the end of that month. The Date table is the only date table on the axis, so the month label means ship month for this measure and order month for [Sales Amount].
The order of the two filter arguments does not matter. CALCULATE evaluates its filter arguments in the original filter context, and the relationship change takes effect when the filters are applied to the fact table.
Other time intelligence functions
The same pattern works for any function that returns dates from the Date table.
Shipped Sales PY =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
SAMEPERIODLASTYEAR ( 'Date'[Date] )
)
Shipped Sales YoY % =
VAR Current =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)
RETURN
DIVIDE ( Current - [Shipped Sales PY], [Shipped Sales PY] )Shipped Sales YoY % repeats USERELATIONSHIP in its own Current variable because a plain [Sales Amount] would use the order-date relationship. A measure that references another measure only inherits the filter context of the caller, not an activated relationship that was not passed down. Each measure that needs the ship-date role has to say so, or call a measure that already does.
You can reuse an existing ship-date measure instead of repeating the expression:
Shipped Sales Amount =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)
Shipped Sales YTD (reuse) =
CALCULATE ( [Shipped Sales Amount], DATESYTD ( 'Date'[Date] ) )This works because the inner CALCULATE inside [Shipped Sales Amount] still activates the relationship while it evaluates, and the outer DATESYTD filter is already in the filter context when it does.
Date table requirements
Time intelligence needs a well-formed Date table. Check these points before blaming the measure:
- The Date table has one row per day, with no gaps, and covers every ship date in
Sales. - It is marked as the date table, or its date column is otherwise recognized by Power BI.
- Ship dates are date values with no time portion. A time part stops a datetime from matching a plain date.
- You filter on
'Date'[Date]or another column from the Date table, not onSales[ShipDate].
Orders that have not shipped have a blank ShipDate. These rows do not match any date, so they fall out of every ship-date measure by month or year. They only appear in the grand total if the total has no date filter. A shipped-sales total therefore can differ from an order-based total.
Common errors
| Symptom | Likely cause |
|---|---|
| Ship-date YTD equals order-date YTD | `USERELATIONSHIP` is missing, or the measure calls a base measure from a different calculation |
| Error about the relationship columns | The columns passed do not match an existing relationship, or the relationship is already active in the opposite role |
| Later months blank | The Date table ends before the latest ship date |
| YTD resets at the wrong time | The fiscal year end is not passed to `DATESYTD` |
Exercise
A matrix shows 'Date'[Year] on rows. [Sales Amount] shows 2025 as 1.2M. You write Shipped Sales PY with USERELATIONSHIP on ShipDate and SAMEPERIODLASTYEAR. The 2025 row shows the amount shipped in 2024. Is the measure correct, and what does it mean that an order placed in December 2024 and shipped in January 2025 appears in the 2025 row of [Shipped Sales Amount]?
Show answer
The measure is correct. In each row, the year comes from the Date table and is applied through ShipDate, so SAMEPERIODLASTYEAR returns the previous year's ship dates and the 2025 row shows 2024 shipments. The order placed in December 2024 and shipped in January 2025 belongs to 2025 for every ship-date measure, but to 2024 for [Sales Amount], which uses OrderDate. The two measures count the same sale in different years by design.