Period-over-period growth that adapts to months and years with ISINSCOPE
One growth measure that compares a month with the previous month and a year with the previous year, and stays blank at the grand total, using ISINSCOPE and SWITCH.
You will learn to
- Detect which level of a matrix you are on with ISINSCOPE
- Choose the comparison period with SWITCH(TRUE())
- Keep growth blank where no fair comparison exists
How it works
In a matrix with years that expand into months, a single “growth” column should mean different things at each level: a **month** compared with the previous month, a **year** with the previous year, and at the **grand total** nothing at all (there is no “previous everything”).
`ISINSCOPE(column)` tells you whether the visual is currently grouping by that column. In a month row both Year and Month Year are in scope, in a year subtotal only Year, and at the grand total neither. So test the **most detailed level first**:
`SWITCH(TRUE(), ISINSCOPE(month column), …, ISINSCOPE(year column), …)` returns the first branch that is true, and blank when none is.
Put the prior value in a variable. With no branch true it is blank, and `DIVIDE` turns a blank prior into a blank result, which is the safeguard: no prior period, no growth figure.
Practice it hands-on with a real data model and a live report that updates as you type.
Prior Period Units = SWITCH(TRUE(), ISINSCOPE('Date'[Month Year]), CALCULATE([Total Quantity], DATEADD('Date'[Date], -1, MONTH)), ISINSCOPE('Date'[Year]), CALCULATE([Total Quantity], DATEADD('Date'[Date], -1, YEAR)))