Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Simplify dax formula and remove errors

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:

 

 

Dax_Cumulated_duplications.png

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

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

 

If 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 regards
Denis
 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hello @selimovd, thank you very much for responding  your tricks really help me resolving the issues that I have.

Hey @Anonymous ,

 

I'm happy you could solve that 😊

 

Best regards

Denis

selimovd
Super User
Super User

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

 

If 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 regards
Denis
 

Hey @Anonymous ,

 

did it work with the measure I posted?

I'm curious if you could solve this issue 🙂

 

If you need any help please let me know.
If it worked I would be happy if you could mark my post as a solution ✔️. Like this, the next person with a similar problem knows if that approach is viable.
 
Best regards
Denis
 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.