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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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