Sub topic 14
Common pitfalls and how to check your measures
This chapter assumes you have built the date table and the year-to-date, prior-year, and moving-average measures from the earlier chapters. It covers why those measures return wrong numbers and how to test them before you publish.
Pitfalls that produce wrong numbers
Most time intelligence bugs come from the date table, not from the measure.
| Symptom | Likely cause | Fix |
|---|---|---|
| Prior-year or DATEADD results are blank or wrong | Missing days in the date table | Rebuild with CALENDAR so every day exists |
| Measures ignore the date filter | Relationship uses the wrong column, or is missing | Relate `Date[Date]` to the fact table's date column |
| Year-to-date works on the fact column but not on the Date table | Visual uses `Sales[Order Date]` instead of `'Date'[Date]` | Put Date table columns on rows and axes |
| Totals match nothing, dates never join | Fact dates contain a time part | Use a date-only column or convert with `INT` or `DATE` |
| Sales for the latest year are missing | Date table ends too early | Extend the CALENDAR end date |
| YTD line runs flat to December | Future dates inherit the last total | Blank them (see below) |
Two details matter most. Time intelligence functions need one row per day with no gaps, and they must filter a column from the date table, not from the fact table. A date table that is marked as a date table but still has gaps passes the marking step and fails silently.
Check the date table first
Add these measures to a card and read the results.
First Date = CALCULATE ( MIN ( 'Date'[Date] ), ALL ( 'Date' ) )
Last Date = CALCULATE ( MAX ( 'Date'[Date] ), ALL ( 'Date' ) )
Missing Days =
VAR FirstDay = [First Date]
VAR LastDay = [Last Date]
RETURN
( DATEDIFF ( FirstDay, LastDay, DAY ) + 1 )
- CALCULATE ( COUNTROWS ( 'Date' ), ALL ( 'Date' ) )Missing Days must be 0. First Date must be on or before your earliest sale, and Last Date on or after your latest.
Compare a measure against a manual calculation
A trusted check is a second measure that reaches the same number a different way. This one rebuilds year to date with an explicit filter.
Sales YTD Check =
CALCULATE (
[Total Sales],
FILTER (
ALL ( 'Date' ),
'Date'[Year] = MAX ( 'Date'[Year] )
&& 'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
Sales YTD Difference = [Sales YTD] - [Sales YTD Check]Put both in a matrix by month. The difference should be 0 in every row. For prior year, pick one month, filter the fact table for the same month a year earlier, and compare the raw total with [Sales PY].
Grain and filter context traps
- A moving average built on
DATESINPERIODuses the last visible date. In a month-level visual that date is the month end, so the window is the 30 days before the month end, not 30 days per day. AVERAGEXover days skips days where[Total Sales]is blank. If weekends have no sales, a 30-day average divides by fewer than 30 days. Decide whether that is what you want.- A slicer on
'Date'[Year]removes other years from the filter context. Time intelligence functions still work with it, because they move dates inside the filtered date table. If the prior-year value is blank for the first year in the slicer, the earlier year was filtered out by something other than the time function, such as a filter on the fact table. - A fiscal year end passed to
TOTALYTDis a text string such as"6-30". A wrong string either errors or resets on the wrong day.
Blank out future dates
Year-to-date measures keep returning the last total for dates with no data. The capped measure from the earlier chapter stops the line at the last sale.
Sales YTD Capped =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[Order Date] ), ALL ( 'Date' ) )
RETURN
IF ( MAX ( 'Date'[Date] ) <= LastSaleDate, [Sales YTD] )A quick troubleshooting path
Exercise
Your Sales PY measure returns blank for March 2024, but the fact table has sales in March 2023. Name two checks to run before changing the measure.
Show answer
Check that Missing Days is 0, because gaps in the date table break SAMEPERIODLASTYEAR and DATEADD. Then check that the visual uses 'Date'[Date] (or another Date table column) and that the relationship joins Date[Date] to the fact table's date column. Also confirm the fact dates have no time part.