Sub topic 8
Year-over-year change and growth percentage
This chapter builds on the prior-year measure from the previous chapter. It assumes you have these in place:
- A contiguous date table marked as the model's date table, related to the fact table.
- A base measure
[Total Sales]. - A prior-year measure
[Sales PY]built withSAMEPERIODLASTYEAR. - Familiarity with variables (
VAR/RETURN) andDIVIDE.
Here you turn the current and prior-year totals into two comparison measures. One is an absolute change and the other is a percentage. You will also see where each can return misleading results.
The two questions a comparison answers
Year-over-year (YoY) analysis asks two different questions:
- How much did it change? This is the absolute difference, such as +120,000 in sales.
- How fast did it change? This is the growth percentage, such as +8.4%.
Both use the same two inputs, the current period and the same period one year earlier. Each should be its own measure, so a report can show either one, and so you can test them separately.
The base measures
These are the measures from earlier chapters. The YoY measures depend on them.
Total Sales = SUM ( Sales[Sales Amount] )
Sales PY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )[Sales PY] does not store anything. In each cell of a visual, it takes the dates in the current filter context, moves them back one year, and evaluates [Total Sales] on those dates.
Growth percentage
The growth percentage measure from this tutorial's plan is:
Sales YoY % =
VAR CurrentSales = [Total Sales]
VAR PriorSales = [Sales PY]
RETURN
DIVIDE ( CurrentSales - PriorSales, PriorSales )The formula is (current - prior) / prior. The variables do two jobs:
- Each measure is evaluated once and the result is reused. Without variables,
[Sales PY]would appear twice and run twice. - The
RETURNline reads like the formula, which makes it easier to review.
Variables are evaluated in the filter context where they are defined. Inside a measure, that is the context of the current cell, so each variable holds the correct value for that cell.
What DIVIDE does with edge cases
DIVIDE takes an optional third argument, the alternate result, used when the denominator is zero or blank. The default is blank.
| Current sales | Prior sales | `Sales YoY %` result |
|---|---|---|
| 1,100 | 1,000 | 0.10 (shown as 10%) |
| 800 | 1,000 | -0.20 (shown as -20%) |
| 500 | blank | blank |
| 500 | 0 | blank |
| blank | 1,000 | -1.00 (shown as -100%) |
The last row can surprise people. If a period has no sales at all, CurrentSales - PriorSales treats the blank as zero, so the result is -100%. That is arithmetically correct, but you should decide whether it is what the report should say. For a store that closed, -100% is true. For a month that has not been loaded yet, it is misleading. The section on incomplete periods below deals with that case.
You can also use the alternate result to show something other than blank, for example DIVIDE ( CurrentSales - PriorSales, PriorSales, 0 ). Use that sparingly. Showing 0% growth for a product that had no sales last year hides the fact that growth cannot be computed. Blank is usually the honest answer.
Absolute change
The absolute change measure looks simpler, but it has a trap:
Sales YoY Change =
VAR CurrentSales = [Total Sales]
VAR PriorSales = [Sales PY]
RETURN
IF (
NOT ISBLANK ( PriorSales ),
CurrentSales - PriorSales
)Without the IF, a product launched this year has a blank PriorSales. DAX treats blank as zero in subtraction, so the change would equal the full current sales. That can be right, since sales really did grow by that amount. But a total row would then mix real changes with launches, and the change would disagree with the percentage column, which is blank for the same rows.
With the IF, both measures are blank for the same rows. If you want new items counted as growth, remove the IF. What matters is that the two measures follow the same rule.
A complete comparison table
Put the measures in a matrix with 'Date'[Year] on the rows to see the full pattern.
| Year | Total Sales | Sales PY | Sales YoY Change | Sales YoY % |
|---|---|---|---|---|
| 2022 | 900,000 | blank | blank | blank |
| 2023 | 1,008,000 | 900,000 | 108,000 | 12.0% |
| 2024 | 957,600 | 1,008,000 | -50,400 | -5.0% |
The first year has no prior year in the data, so both comparison measures are blank. That is correct behavior and needs no fix.
Comparing year-to-date with year-to-date
Putting the monthly YoY % on a line chart is fine. Comparing a running total is where mistakes happen. Suppose today is in October and you want to know whether this year is ahead of last year so far. Comparing [Sales YTD] to the full prior-year total ([Sales PY] at the year level) would compare 10 months against 12.
Instead, shift the YTD measure itself:
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )
Sales YTD PY =
CALCULATE ( [Sales YTD], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Sales YTD YoY % =
VAR CurrentYTD = [Sales YTD]
VAR PriorYTD = [Sales YTD PY]
RETURN
DIVIDE ( CurrentYTD - PriorYTD, PriorYTD )Nesting works because of the evaluation order. CALCULATE first moves the date filter back one year. The TOTALYTD inside then reads the last date of that shifted context and sums from January 1 of that earlier year up to it. At the month level for March 2025, the shifted context ends in March 2024, so you get January through March 2024. Both sides of the comparison cover the same span.
When the current period is incomplete
In the middle of a month, [Total Sales] covers only some days, but [Sales PY] for the same month, shifted back a year, covers the whole month. The YoY % then looks like a steep decline. There are two usual ways to handle this:
- Blank the incomplete period. Use the capped pattern from the incomplete-periods chapter so that the measure returns blank for dates after the last sale.
- Compare equal spans. Use the month-to-date or year-to-date versions, which stop at the same day in both years.
A third option is to cap the prior year at the same day. That needs more logic than this chapter covers, so use the first two unless the report truly needs it.
Using DATEADD instead
SAMEPERIODLASTYEAR is a fixed one-year shift. DATEADD ( 'Date'[Date], -1, YEAR ) gives the same result for this case. Use DATEADD when you also need other shifts, such as -1, QUARTER for quarter-over-quarter or -1, MONTH for month-over-month. The growth formula stays the same. Only the prior-period measure changes:
Sales PM =
CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )
Sales MoM % =
VAR CurrentSales = [Total Sales]
VAR PriorSales = [Sales PM]
RETURN
DIVIDE ( CurrentSales - PriorSales, PriorSales )This is why separating the prior-period measure from the growth measure pays off. You reuse the growth pattern and swap the input.
Checking your results
Test the growth measures with a few quick checks:
- Put
Year,[Total Sales],[Sales PY], and the YoY measures in one matrix. The[Sales PY]value in each row must equal[Total Sales]in the row above. - Compute one percentage by hand for a single year and compare it.
- Check that the first year in the data shows blank, not 0% or -100%.
- Filter a slicer to one product that was launched mid-period and confirm the change and percentage agree on blanks.
If [Sales PY] is blank everywhere, the cause is usually a date table that is not marked as one, not related to the fact table, or has gaps. Fix the date table before editing the measure.
Exercise
A product was first sold in 2024 with sales of 50,000. In a matrix by year, what do [Sales YoY Change] (with the IF ( NOT ISBLANK ( PriorSales ), ... ) guard) and [Sales YoY %] show for 2024? What does [Sales YoY Change] show if you remove the guard, and why might that be a problem?
Show answer
With the guard, both measures are blank for 2024, because [Sales PY] is blank and the IF returns blank. DIVIDE also returns blank when the denominator is blank. Without the guard, DAX treats the blank prior-year value as zero in the subtraction, so the change shows 50,000. The percentage is still blank, so the two columns disagree for the same row, and totals that include the product mix launches with real growth.
Exercise
You want to know whether this year is ahead of last year as of today, which is in October. Why is DIVIDE ( [Sales YTD] - [Sales PY], [Sales PY] ) evaluated at the year level wrong, and which measure should replace [Sales PY]?
Show answer
At the year level, [Sales PY] is the prior year's full 12-month total, while [Sales YTD] covers only January to October of the current year, so the growth looks far too low. Replace [Sales PY] with [Sales YTD PY], defined as CALCULATE ( [Sales YTD], SAMEPERIODLASTYEAR ( 'Date'[Date] ) ), so both sides cover January to October.