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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
alexvanlauwe
New Member

Measure with multiple conditions

Hello to all,

 

So , I will try to explain my problem as precise as possible.

 

I would like to develop a measure with multiple conditions to determine the situation of the market :

 

I have first develop 2 others measures TM[TM3MR%VARPY] and TM[TM12MR%VARPY] that represent

  • the variation between total market 3 month rolling and total market 3 month rolling previous year
  • the variation between total market 12 month rolling and total market 12 month rolling previous year.

Then I would like to express a DAX function for multiple conditions to determine the situation the market :

If TM[TM3MR%VARPY]>0 && TM[TM12MR%VARPY]<0,"RECOVERY"

if TM[TM3MR%VARPY]>=0,02 && TM[TM12MR%VARPY]>=0,02,"EXPANSION"

if TM[TM3MR%VARPY]>TM[TM12MR%VARPY] && TM[TM3MR%VARPY]<0,02,"PEAK"

if TM[TM3MR%VARPY]<[TM12MR%VARPY],"MATURITY"

if [TM3MR%VARPY]<0 && [TM12MR%VARPY]>0,"CONTRACTION",
if [TM3MR%VARPY]<0 && [TM12MR%VARPY]<0,"TROUGH")
 

Then I try to use the "SWITCH" DAX function for multiple conditions but seems that it's something that don't master

see below

 

Measure = SWITCH TRUE(), TM[TM3MR%VARPY]>0 && TM[TM12MR%VARPY]<0,"RECOVERY",TM[TM3MR%VARPY]>=0,02 && TM[TM12MR%VARPY]>=0,02,"EXPANSION",TM[TM3MR%VARPY]>TM[TM12MR%VARPY] && TM[TM3MR%VARPY]<0,02,"PEAK",TM[TM3MR%VARPY]<[TM12MR%VARPY],"MATURITY",[TM3MR%VARPY]<0 && [TM12MR%VARPY]>0,"CONTRACTION",[TM3MR%VARPY]<0 && [TM12MR%VARPY]<0,"TROUGH")
 
Could you please help me with this?
 
Many thanks in advance for your help.

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You are missing "(" after SWITCH.  Also, I would first store your two measures as variables and then use the variables in the SWITCH evaluations.  The way it is written will cause a lot of recalculation.  Partial example below (note that you should not include the table name when referencing measures so other knows it is a measure and not a column reference).

 

Measure =
VAR varpy3M = [TM3MR%VARPY]
VAR varpy12M = [TM12MR%VARPY]
RETURN
    SWITCH (
        TRUE (),
        varpy3M > 0
            && varpy12M < 0"RECOVERY",
        varpy3M >= 0.02
            && TM[TM12MR%VARPY] >= 0.02"EXPANSION",
        "Other"
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

You are missing "(" after SWITCH.  Also, I would first store your two measures as variables and then use the variables in the SWITCH evaluations.  The way it is written will cause a lot of recalculation.  Partial example below (note that you should not include the table name when referencing measures so other knows it is a measure and not a column reference).

 

Measure =
VAR varpy3M = [TM3MR%VARPY]
VAR varpy12M = [TM12MR%VARPY]
RETURN
    SWITCH (
        TRUE (),
        varpy3M > 0
            && varpy12M < 0"RECOVERY",
        varpy3M >= 0.02
            && TM[TM12MR%VARPY] >= 0.02"EXPANSION",
        "Other"
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,

 

Finally it works , I found my mistake (Stupid mistake 😁)

 

Thank you again for your help !

Dear Pat,

 

thank you for your answer.

 

I tried your solution but I have another problem now. When I want to vizualize my measure , Power BI told me that

 
 
 

SWITCH does not support comparing values of type TRUE/FLASE with values of type text.

Consider using the value or format function to convert one of the values

 

So I convert the text results with value function but I have still the same message.

 

Please see below my measure:

 

Measure =
VAR varpy3M = [TM3MR%VARPY]
VAR varpy12M = [TM12MR%VARPY]
RETURN
SWITCH(
TRUE(),
varpy3M >0 && varpy12M<0,VALUE("Recovery"),
varpy3M >=0,02 && varpy12M>=0,02,VALUE("Expansion"),
varpy3M > varpy12M && varpy3M<0,02,VALUE("Peak"),
varpy3M < varpy12M,VALUE("Maturity"),
varpy3M<0 && varpy12M>0,VALUE("Contraction"),
varpy3M<0 && varpy12M<0,VALUE("Trough"))
 
If you have any idea ? thank you again for your help
 
Kind regards
MattAllington
Community Champion
Community Champion

It's hard to tell based on this information. The most likely issue is that you have to get the order of these correct. Switch will stop on the first result that returns true. If you can't work out what is happening I suggest you write each component as a simpnle measure and see what they return. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.