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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
MDKCLIRResearch
Helper III
Helper III

Extra closing parenthesis added to a DAX Switch statement

I need to do conditional formatting based on two fields instead of one.  To do this, I created a switch statement that creates an integer state variable that (I hope) can be used in conditional formatting. 

 

There are four basic states that each have a different background color:

1. Extreme

2. Loud

3. Moderate

4. Quiet

 

For each of the four states, I need to set the font color to hide 0 entries or display entries that are higher than 0. (So 4 times 2 = 8 states).

 

However, when I hit Enter to complete my DAX statement based on a SWITCH expression, additional closing parameters are automatically added to the end.  The additional closing parenthesis make the DAX statement invalid.

 

The DAX Statement that I am trying to create is below.  

 

12amState = SWITCH(MAX([NoiseCategory],0),
                   1, IF(MAX([12am],0)=0, 1, 2),
                   2, IF(MAX([12am],0)=0, 3, 4),
                   3, IF(MAX([12am],0)=0, 5, 6),
                      IF(MAX([12am],0)=0,7,8))

 

 

When I hit Enter to complete the DAX Statement, additional parenthesis are added and the expression is flagged with a syntax error.

 

3 REPLIES 3
Anonymous
Not applicable

Hi @MDKCLIRResearch ,

 

Please check the example I tested. It works fine and it is a calculated column.

vstephenmsft_0-1637721754420.png

You added 0 to the MAX function. This is to compare [12am] with 0 and then take the maximum value.

vstephenmsft_2-1637722323778.png

 

If you want to create a measure, you cannot use MAX([12am],0).

vstephenmsft_1-1637722310834.png

 

Can you provide some sample data and expected results? In this way, I can help you modify the formula according to the logic of your expected result.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

AlexisOlson
Super User
Super User

Does it help if you use a variable?

 

12amState =
VAR Max0 = ( MAX ( [12am], 0 ) = 0 )
RETURN
    SWITCH (
        MAX ( [NoiseCategory], 0 ),
        1, IF ( Max0, 1, 2 ),
        2, IF ( Max0, 3, 4 ),
        3, IF ( Max0, 5, 6 ),
        IF ( Max0, 7, 8 )
    )
ERD
Community Champion
Community Champion

@MDKCLIRResearch ,

As far as I can see, you are creating a calculated column.. I don't see any issues:

12amState = 
SWITCH (
    MAX ( [NoiseCategory], 0 ),
    1, IF ( MAX ( [12am], 0 ) = 0, 1, 2 ),
    2, IF ( MAX ( [12am], 0 ) = 0, 3, 4 ),
    3, IF ( MAX ( [12am], 0 ) = 0, 5, 6 ),
    IF ( MAX ( [12am], 0 ) = 0, 7, 8 )
)

You can check your formula here for syntax errors and for better formatting: https://www.daxformatter.com/

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors