cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
malikaditya New Member
New Member

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

Accepted Solutions
Gordonlilj Established Member
Established Member

Re: Help with transforming case to switch

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
Gordonlilj Established Member
Established Member

Re: Help with transforming case to switch

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

jbarnes Member
Member

Re: Help with transforming case to switch

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.
                

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 147 members 1,646 guests
Please welcome our newest community members: