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.
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")
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
100 | |
78 | |
76 | |
52 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |