Forum Discussion
Simplify dax formula and remove errors
- 5 years ago
Hey Anonymous ,
the error with the MAX expression is a little annoying. You can save the value of MAX in a variable, that should fix it.
For the many ifs I would use SWITCH with TRUE in combination instead:
https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/
So the formula could look like this:
Cumulated Sum = VAR vMaxDate = YEAR(MAX(Abfrage1[fiscaldate])) VAR vYear_1 = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = 2020)) VAR vYear_2 = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = 2021)) -- and so on RETURN SWITCH( TRUE(), vMaxDate = 2020, vYear_1, vMaxDate = 2021, vYear_2 -- and so on )I don't fully understand your approach. For me it looks like you use the MAX value for the calculate. Then you could just add it dynamically from the variable:
Cumulated Sum = VAR vMaxDate = YEAR(MAX(Abfrage1[fiscaldate])) VAR vResult = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = vMaxDate )) RETURN vResultIf you need any help please let me know.If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍Best regardsDenisBlog: WhatTheFact.biFollow me: twitter.com/DenSelimovic
Hey Anonymous ,
the error with the MAX expression is a little annoying. You can save the value of MAX in a variable, that should fix it.
For the many ifs I would use SWITCH with TRUE in combination instead:
https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/
So the formula could look like this:
Cumulated Sum =
VAR vMaxDate = YEAR(MAX(Abfrage1[fiscaldate]))
VAR vYear_1 = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = 2020))
VAR vYear_2 = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = 2021))
-- and so on
RETURN
SWITCH( TRUE(),
vMaxDate = 2020, vYear_1,
vMaxDate = 2021, vYear_2
-- and so on
)
I don't fully understand your approach. For me it looks like you use the MAX value for the calculate. Then you could just add it dynamically from the variable:
Cumulated Sum =
VAR vMaxDate = YEAR(MAX(Abfrage1[fiscaldate]))
VAR vResult = CALCULATE( [AverageBudgetYear], FILTER( ALL(Abfrage1[fiscaldate]), vMaxDate = vMaxDate ))
RETURN
vResult
Hey Anonymous ,
did it work with the measure I posted?
I'm curious if you could solve this issue 🙂