Sub topic 13
Blanking future and incomplete periods
This chapter assumes you have a marked date table, a working [Total Sales] measure, and the year-to-date measure from the earlier chapters. You should also be comfortable with CALCULATE and variables.
Why future dates show values
A date table usually covers whole years, such as 2020 to 2025. Sales data stops earlier, perhaps in the middle of the current year. A year-to-date measure still returns a value for every later date in the table. Each of those dates has no sales of its own, but the year-to-date window still includes all earlier sales in the year. The total stays the same, so a line chart runs flat to December.
The flat line suggests that sales were steady, when in fact the data has not arrived yet.
Find the last date with data
The fix has two steps. First find the last date that has a sale. Then return a value only for dates up to that point.
Sales YTD Capped =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[Order Date] ), ALL ( 'Date' ) )
IF ( MAX ( 'Date'[Date] ) <= LastSaleDate, [Sales YTD] )The listing above is missing its RETURN line, so use this corrected form:
Sales YTD Capped =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[Order Date] ), ALL ( 'Date' ) )
RETURN
IF ( MAX ( 'Date'[Date] ) <= LastSaleDate, [Sales YTD] )Each part has a job:
MAX ( Sales[Order Date] )reads the latest order date in the fact table.ALL ( 'Date' )removes the date filters from the visual. Without it, the maximum would be limited to the current row or column and would change from one cell to the next.MAX ( 'Date'[Date] )is the last date visible in the current cell. For a day, that is the day. For a month, it is the month's last day.IFhas no else branch, so it returns blank when the condition is false. Visuals skip blank points, so the line stops.
What happens in the current period
The comparison uses the last visible date. In a monthly visual, the current month is not blank if the data ends partway through it. The month ends on the 31st, which is later than the last sale on the 14th, so MAX ( 'Date'[Date] ) is greater than LastSaleDate and the month is blanked.
That may hide a month that has partial data. Decide which behavior you want:
| Goal | Condition |
|---|---|
| Show only complete periods | `MAX ( 'Date'[Date] ) <= LastSaleDate` |
| Show the period that contains the last sale | `MIN ( 'Date'[Date] ) <= LastSaleDate` |
Showing the partial month means the last point is smaller than the others. When you compare it with the prior year, it will look like a drop. Label the visual, or use a month-to-date comparison for the current month.
Sales YTD Through Current Period =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[Order Date] ), ALL ( 'Date' ) )
RETURN
IF ( MIN ( 'Date'[Date] ) <= LastSaleDate, [Sales YTD] )Apply the cap to related measures
A capped year-to-date measure does not cap other measures. If [Sales YoY %] uses [Sales YTD], it can still show a value for future dates, because the prior-year side has data. Build the comparison measures on the capped measure, or put the same test in each measure.
Sales PY Capped =
VAR LastSaleDate =
CALCULATE ( MAX ( Sales[Order Date] ), ALL ( 'Date' ) )
RETURN
IF ( MAX ( 'Date'[Date] ) <= LastSaleDate, [Sales PY] )Check the result
- Put
Date[Date]on a table visual with[Sales YTD]and[Sales YTD Capped]. - Scroll to the last sale date and the days after it.
- Confirm that the capped column is blank after the last sale and that the two columns match before it.
Exercise
A monthly line chart uses a measure that returns blank when MAX ( 'Date'[Date] ) is later than the last sale date. The last sale is on 14 March. Is the March point shown, and which change would show it?
Show answer
March is not shown, because its last visible date, 31 March, is later than 14 March. Change the test to MIN ( 'Date'[Date] ) <= LastSaleDate. The first day of March is before 14 March, so the point is shown.