March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Newbiw here to Power BI and DAX. I am looking to calculate the percentage difference in year on year values and then writing the derived value in a new column.Ive written the following DAX formula but it keeps saying theres a syntax error so not sure what I am doing wrong. I would be grateful if anyone can point me in the right direction:
PercentageChange =
VAR PrevYrGrowth =
CALCULATE(
MAX('PProj'[P Growth]),
'PProj'[CName] = EARLIER('PProj'[CName]) &&
'PProj'[Year] = EARLIER('PProj'[Year]) - 1
)
RETURN
IF(
NOT(ISBLANK(PrevYrGrowth)),
(('PProj'[P Growth] - PrevYrGrowth) / PrevYrGrowth) * 100,
BLANK()
)
Solved! Go to Solution.
Hi @riffraff55
I would recommend building it as a measure instead of a calculated column, but if you still insist it being a column this should work:
PercentageChange =
VAR _Year = [Year]
VAR _CY =
CALCULATE(
SUM(PProj[P Growth]),
FILTER(ALL(PProj), [CName] = EARLIER([CName]) && [Year] = _Year)
)
VAR _PY =
CALCULATE(
SUM(PProj[P Growth]),
FILTER(ALL(PProj), [CName] = EARLIER([CName]) && [Year] = _Year - 1)
)
RETURN
DIVIDE(_CY - _PY, _PY) * 100
just for my learning exprience, what would be the difference in creating it as a measure rather than as a column? is it just good practice or is the coding completely different?
Hi @riffraff55 ,
They're both DAX specific expressions and each of them have their advantages. Having it as a measure gives you more flexibility and can give you results based on visual level context at the aggregate level and does not take up memory, thus letting your model refresh faster.
But if you want to do specific row level calculations, then calculated column(s) may be better suited, but do note that on reresh, these columns are calculated which may slow down your model refresh.
Hi @riffraff55
I would recommend building it as a measure instead of a calculated column, but if you still insist it being a column this should work:
PercentageChange =
VAR _Year = [Year]
VAR _CY =
CALCULATE(
SUM(PProj[P Growth]),
FILTER(ALL(PProj), [CName] = EARLIER([CName]) && [Year] = _Year)
)
VAR _PY =
CALCULATE(
SUM(PProj[P Growth]),
FILTER(ALL(PProj), [CName] = EARLIER([CName]) && [Year] = _Year - 1)
)
RETURN
DIVIDE(_CY - _PY, _PY) * 100
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |