Forum Discussion
TCavins
11 months agoHelper V
Table % Change from Previous Row
I have a simple table that has 2 columns. Year SUM Units I would like to add a third column that gets the % Change of Sum Units for each row compared to the previous year. I'm likely overthi...
- 11 months ago
Here's the solution I developed combining various sources I found. It may not be the most condensed but it works:
Units % Changed = VAR CurrentRowDate = MAX(MYTABLE[Year]) var currentUnits = CALCULATE( SUM(MYTABLE[Units]), FILTER( ALLSELECTED(MYTABLE), MYTABLE[Year] = CurrentRowDate)) VAR previousUnits = CALCULATE( SUM(MYTABLE[Units]), FILTER( ALLSELECTED(MYTABLE), MYTABLE[Year] = CALCULATE ( MAX(MYTABLE[Year]), FILTER(ALLSELECTED(MYTABLE), MYTABLE[Year] < CurrentRowDate) ) ) ) var percentChanged = (currentUnits - previousUnits) / previousUnits RETURN IF(ISBLANK(previousUnits), BLANK(),percentChanged)
TCavins
11 months agoHelper V
Here's the solution I developed combining various sources I found. It may not be the most condensed but it works:
Units % Changed =
VAR CurrentRowDate = MAX(MYTABLE[Year])
var currentUnits = CALCULATE(
SUM(MYTABLE[Units]),
FILTER(
ALLSELECTED(MYTABLE),
MYTABLE[Year] = CurrentRowDate))
VAR previousUnits =
CALCULATE(
SUM(MYTABLE[Units]),
FILTER(
ALLSELECTED(MYTABLE),
MYTABLE[Year]
= CALCULATE (
MAX(MYTABLE[Year]),
FILTER(ALLSELECTED(MYTABLE), MYTABLE[Year] < CurrentRowDate)
)
)
)
var percentChanged = (currentUnits - previousUnits) / previousUnits
RETURN IF(ISBLANK(previousUnits), BLANK(),percentChanged)