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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
malikaditya
Frequent Visitor

Help with transforming case to switch

Hi,

 

I need to transform a case statement from SQL to switch in power bi desktop. My case statement looks like this:

 

Case
When TV >= 100 And UC In ('A', 'B', 'C', 'D') Then 'TD'
When TV >= 10 and TV < 20 And UC In ('A', 'B', 'C', 'D') Then 'TDA'
When TV >= 20 And UC In ('E') And PE Not In ('1', '2') Then 'TD'
When TV >= 10 and TV < 20 And UC In ('E') And PE Not In ('1', '2') Then 'TDA'
ELSE Lower

 

I am not able to figure out how I can pass multiple conditions in switch. Help!!!

1 ACCEPTED SOLUTION
Gordonlilj
Solution Sage
Solution Sage

Hi,

 

You could try something like

 

Calc = 

SWITCH(TRUE(),'Table'[TV] >= 100 && 'Table'[UC] IN {"A","B","C","D"},"TD",
'Table'[TV] >= 10 && 'Table'[TV] <20 && 'Table'[UC] IN {"A","B","C","D"},"TDA",
'Table'[TV] >=20 && 'Table'[UC] IN {"E"} && NOT('Table'[PE]) IN {"1","2"},"TD",
'Table'[TV] >= 10 && 'Table'[TV] < 20 && 'Table'[UC] IN {"E"} && NOT('Table'[PE]) IN {"1","2"},"TDA","Lower")

 

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

I would use an IF.

 

variable =  if(TV >= 10 && UC = "A" || UC = "B" || UC = "C" ||  UC = "D"), "TDA",
                 if(TV >= 100 && UC = "A" || UC = "B" || UC = "C" ||  UC = "D"), "TD",
"Lower"))

^^something like this, I tend to build the first line to check the logic and then expand the nested statements.
                

Gordonlilj
Solution Sage
Solution Sage

Hi,

 

You could try something like

 

Calc = 

SWITCH(TRUE(),'Table'[TV] >= 100 && 'Table'[UC] IN {"A","B","C","D"},"TD",
'Table'[TV] >= 10 && 'Table'[TV] <20 && 'Table'[UC] IN {"A","B","C","D"},"TDA",
'Table'[TV] >=20 && 'Table'[UC] IN {"E"} && NOT('Table'[PE]) IN {"1","2"},"TD",
'Table'[TV] >= 10 && 'Table'[TV] < 20 && 'Table'[UC] IN {"E"} && NOT('Table'[PE]) IN {"1","2"},"TDA","Lower")

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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