Sub topic 10
Pitfalls: blank dates, wrong columns, and unexpected totals
This chapter assumes you can build a star schema in Power BI or a Tabular model. It also assumes you can write CALCULATE measures and have already created an inactive Sales[ShipDate] to 'Date'[Date] relationship. The goal is to help you recognize the failure patterns of USERELATIONSHIP and diagnose them quickly.
Most problems fall into three groups. Some rows have no date to match. The function is pointed at the wrong columns. Or the numbers are correct but not what the reader expected.
The sample data
The examples use a small Sales table. The active relationship joins Sales[OrderDate] to 'Date'[Date]. The inactive relationship joins Sales[ShipDate] to 'Date'[Date].
| OrderID | OrderDate | ShipDate | SalesAmount |
|---|---|---|---|
| 1 | 2024-12-28 | 2025-01-03 | 100 |
| 2 | 2024-12-30 | (blank) | 50 |
| 3 | 2025-01-02 | 2025-01-05 | 75 |
The measures are the ones from earlier chapters:
Sales Amount = SUM ( Sales[SalesAmount] )Sales Amount by Ship Date =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)A matrix with 'Date'[Year] on rows and both measures as values shows this:
| Year | Sales Amount | Sales Amount by Ship Date |
|---|---|---|
| 2024 | 150 | (blank) |
| 2025 | 75 | 175 |
| (blank) | (blank) | 50 |
| Total | 225 | 225 |
Every pitfall in this chapter can be read from this table. Both measures have the same grand total of 225. Their rows differ because each measure assigns the same fact rows to different years. Order 2 has no ship date, so it lands in the blank row of the ship-date measure.
Blank dates
Why a blank row appears
A relationship in a Tabular model is allowed to be incomplete. If a fact row has a key value with no match in the dimension, the engine keeps the row. It links the row to a hidden blank member of the dimension. This blank member is also called the unknown member, and it is the source of the blank row in the matrix above.
Under the ship-date relationship, a row goes to the blank member in either of two cases:
Sales[ShipDate]is blank, as for an order that has not shipped.Sales[ShipDate]holds a value that does not exist in'Date'[Date].
The first case is usually valid business data. The second is a modeling defect.
Blank dates versus dates outside the calendar
A blank ship date means "not shipped yet". A ship date missing from the Date table means the calendar is too short. For example, the Date table might end on 2025-12-31 while a ship date is in 2026. Both cases show up in the same blank row, so you cannot tell them apart in the visual.
You can tell them apart with two diagnostic measures:
Rows Without Ship Date =
CALCULATE ( COUNTROWS ( Sales ), ISBLANK ( Sales[ShipDate] ) )Ship Dates Missing From Date Table =
COUNTROWS (
FILTER (
Sales,
NOT ISBLANK ( Sales[ShipDate] )
&& ISBLANK ( LOOKUPVALUE ( 'Date'[Date], 'Date'[Date], Sales[ShipDate] ) )
)
)Put both in a card with no date filters. The first number is rows you can legitimately leave in the blank row. If the second number is above zero, extend the Date table or fix the source data.
Time components break matching
Relationships match on exact values. A Date column that contains midnight only will not match a ship date that includes a time, such as 2025-01-03 14:25. The datetime value has no matching row, so the sale falls into the blank member.
This often happens with the ship date and not the order date. The order date may have been cleaned in the source query while the ship date still carries a timestamp. Check the column's data type. Convert the column to the Date type in Power Query, or round it down before loading.
Handling the blank row
You have three reasonable options:
- Leave the blank row. It is accurate, because those orders have not shipped.
- Filter it out of the visual. This hides sales from the visual while the card total still includes them, so label the report.
- Replace blank ship dates in the source with a placeholder date such as
9999-12-31, and add that date to the Date table with a label like "Not shipped". This makes the category visible and sortable, but it will distort any date range or time-intelligence logic that reaches that date.
Option 3 changes the data model, so apply it only if the report needs a named category.
Wrong columns
What USERELATIONSHIP accepts
USERELATIONSHIP takes two column references. They must be the two ends of an existing relationship in the model. The function does not create a join. It only chooses which existing relationship to use inside the CALCULATE call.
This leads to several common failures:
- A column that is not part of a relationship.
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Year] )fails, because'Date'[Year]is not a relationship column. - A relationship that was never created. You may have meant to create a ship-date relationship but only the order-date one exists. The measure then returns an error.
- The wrong dimension. If you duplicated the Date table as
'Ship Date', the ship-date relationship is to'Ship Date'[Date], not'Date'[Date].USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )then fails, and it is also unnecessary. - A different fact column.
Sales[DueDate]andSales[ShipDate]look alike. Copying a measure and changing only the measure name is a frequent cause of a measure that quietly reports the wrong role.
By convention the many-side column comes first and the one-side column second, as in the examples. Follow that convention so the code is easy to read.
-- Fails: 'Date'[Year] is not one end of a relationship
Sales by Ship Year Wrong =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Year] )
)-- Works: both columns are the ends of the inactive relationship
Sales by Ship Year =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)Relationship column versus filter column
Keep two ideas separate. The USERELATIONSHIP columns are the join columns, Sales[ShipDate] and 'Date'[Date]. The columns in the visual, such as 'Date'[Year] or 'Date'[Month], are the filter columns. The filter on 'Date'[Year] reaches Sales over whichever relationship is active inside the measure.
Other situations where it does not work
- Row-level security.
USERELATIONSHIPcannot be used in a measure when row-level security (RLS) is defined on the table that contains the measure. Test this early if your model uses RLS. - The relationship is active already. The function still runs, and it returns the same result as the plain measure. This is a quiet mistake when you meant to use a different relationship.
- The relationship was deleted or disabled. After a model change, an inactive relationship may no longer exist, and the measure that references it starts to fail.
Unexpected totals
The active relationship is switched off, not added
Inside CALCULATE, USERELATIONSHIP replaces the active relationship between those two tables for that calculation. It does not add a second filter path. Within Sales Amount by Ship Date, the Date table no longer filters Sales[OrderDate].
If a report page has a Year slicer, it filters the order year for [Sales Amount] and the ship year for [Sales Amount by Ship Date]. The two measures answer different questions under the same slicer. Their totals will not match, and readers often take the difference for an error. Put the role in the measure name, as in "by Ship Date", and add a note on the visual.
Combining order and ship filters
If you need orders placed in 2024 that shipped in 2025, a single Date table cannot do both. The measure has only one active relationship at a time. One approach is to filter the other date column directly:
Ordered 2024, Shipped Sales =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
'Date'[Year] = 2025,
FILTER ( ALL ( Sales[OrderDate] ), YEAR ( Sales[OrderDate] ) = 2024 )
)This works because FILTER over ALL ( Sales[OrderDate] ) filters the fact column directly, and the relationship to 'Date' is not involved. Even so, a separate 'Order Date' and 'Ship Date' table pair is usually clearer when users need both filters at once.
Time intelligence and the order of arguments
For a year-to-date by ship date, the measure from the earlier chapter is:
Shipped Sales YTD =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
DATESYTD ( 'Date'[Date] )
)CALCULATE evaluates its modifiers first, so USERELATIONSHIP takes effect no matter where it appears in the argument list. DATESYTD produces a set of dates on the Date table, and that set filters Sales through the ship-date relationship. The position of the arguments does not change the result, but placing USERELATIONSHIP first makes the intent easier to read.
One real trap is the date range. The YTD runs from January 1 of the visible year to the last visible date. If the Date table has no row for a ship date, such as one in a year the calendar does not cover, the YTD silently leaves that sale out of every period.
Unshipped orders and running totals
A ship-date YTD never includes order 2 from the sample data. This is correct, because the order has no ship date. If a reader compares ordered YTD with shipped YTD and expects the gap to close at year-end, the gap includes unshipped orders. Explain this in the report instead of changing the measure.
Totals that do not add up
A matrix with the Date hierarchy on rows can show subtotals that differ from the sum of the visible rows. This usually has one of three causes:
- The blank row is hidden by a visual filter, as discussed above.
- A page filter or slicer on the Date table removes dates that some rows still need.
- A measure is mixed from two roles, for example an order-date ratio divided by a ship-date measure.
Check each in that order. Place a card with the plain SUM ( Sales[SalesAmount] ) beside the matrix. If the card matches the matrix total, the model is complete. If it does not, rows are being dropped by a filter.
A diagnostic path
Quick checklist
Run through these steps whenever a new alternate-date measure gives surprising numbers:
- Confirm that the inactive relationship exists, and note which two columns it joins.
- Confirm the two column names in
USERELATIONSHIPmatch those columns exactly. - Check that the fact column is a Date type, not a datetime with a time part.
- Check that the Date table covers every ship date in the data.
- Compare the measure total with a plain
SUMin a card with no filters. - Explain any blank row to the report reader, or remove it at the source.
Exercise
A matrix by 'Date'[Year] shows Sales Amount by Ship Date of 175 for 2025, a blank row of 50, and a grand total of 225. Sales has three rows, and one has a blank ShipDate. A colleague says the blank row is a bug in the relationship. What do you check and what do you tell them?
Show answer
Check whether the 50 comes from a row with a blank ShipDate or from a ship date that is missing from the Date table. Use Rows Without Ship Date and Ship Dates Missing From Date Table. Here the row has a blank ShipDate, so the blank row is correct: the order has not shipped, and the engine assigns it to the blank member of the Date table. The relationship works as designed. If the second measure were above zero, the Date table would need to be extended.
Exercise
This measure returns an error. What is wrong, and how do you fix it? Sales by Ship Month = CALCULATE ( [Sales Amount], USERELATIONSHIP ( Sales[ShipDate], 'Date'[MonthName] ) )
Show answer
'Date'[MonthName] is not an end of any relationship. USERELATIONSHIP needs the two join columns, Sales[ShipDate] and 'Date'[Date]. Use those, and show the month by placing 'Date'[MonthName] on the visual's axis. The filter on that column then reaches Sales over the ship-date relationship inside the measure.
Exercise
Your Date table has one row per day from 2023-01-01 to 2025-12-31. A ship date of 2026-01-04 appears in Sales. What happens to that row in a ship-date YTD visual for 2025, and how do you detect it?
Show answer
The row has no match in the Date table, so it goes to the blank member and is not included in any year, including the 2025 YTD. Detect it with Ship Dates Missing From Date Table, which returns a count above zero. Fix it by extending the Date table beyond the last ship date.