The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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!!!
Solved! Go to Solution.
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")
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.
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")