Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello I'm new to dax and I have some problems with it syntax. I want to create a new mesure named ""cumulated" based on an other mesure "AverageBudgetYear".
Actually I have 2 problems, first I need to remove duplicate lines in code and symplify the syntax and second I need to resolve this error message "A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed".
This is my syntaxe:
Solved! Go to Solution.
Hey @Aymen_Soussi ,
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
Hello @selimovd, thank you very much for responding your tricks really help me resolving the issues that I have.
Hey @Aymen_Soussi ,
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 @Aymen_Soussi ,
did it work with the measure I posted?
I'm curious if you could solve this issue 🙂
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
86 | |
84 | |
83 | |
67 | |
49 |
User | Count |
---|---|
131 | |
111 | |
97 | |
71 | |
67 |