Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi all
I am a new Power BI user, I am trying to use Switch true expression, I am getting the following error for the expression in power query.
My query is
= Table.AddColumn(#"Added Custom", "PIPING-INT", each
SWITCH(TRUE(),
AND([#"SAP Task-3"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT",
AND([#"SAP Task-4"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT",
AND([#"SAP Task-5"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT",
AND([#"SAP Task-6"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT",
AND([#"SAP Task-7"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT",
AND([#"SAP Task-8"] = "PIPING",[#"SAP Task-2"] = "INT"),"PIPING-INT","FALSE"))
I get the error as SWITCH was not recognized, there was int any syntax error also, note that I created only from switch rest auto-created by power query
Solved! Go to Solution.
Hi @Anonymous,
I have modified your custom column syntax try this
= Table.AddColumn(Source, "PIPING-INT", each if Text.Contains([#"SAP Task-3"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-4"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-5"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-6"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-7"],"PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task -8"],"PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else "False")
Thanks
Lavdeep
Hi, @Anonymous
'switch' is not a keyword in Power Query. I'd like to suggest you try using the equivalent 'if... else if ... else...' statement to achieve your requirements.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous
You're mixing up M in Power Query and DAX (the SWITCH function). Can't use DAX in M queries.
Maybe if you explain what you are trying todo and supply some sampe data we can find a solution.
Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Proud to be a Super User!
Thanks Phillip,
I am trying to use switch true in Power bi power query for
converting following nested if using switch
if [#"SAP Task-3"] = "PIPING" and [#"SAP Task-2"] = "INT"then "PIPING-INT" else if [#"SAP Task-4"]="PIPING"and [#"SAP Task-2"]="INT" then "PIPING-INT"else if [#"SAP Task-5"]="PIPING"and [#"SAP Task-2"]="INT" then "PIPING-INT"else if [#"SAP Task-6"]="PIPING"and [#"SAP Task-2"]="INT" then "PIPING-INT"else if [#"SAP Task-7"]="PIPING"and [#"SAP Task-2"]="INT" then "PIPING-INT"else if [#"SAP Task -8"]="PIPING"and [#"SAP Task-2"]="INT" then "PIPING-INT"else "FALSE"
Hi @Anonymous
Can you please supply your PBIX file with sample data. I need to see the structure of your data.
Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Proud to be a Super User!
Hi Philip,
I shall not be able to provide you the same, my question is very simple, How to create Switch true query in Power query editor
Hi @Anonymous,
I have modified your custom column syntax try this
= Table.AddColumn(Source, "PIPING-INT", each if Text.Contains([#"SAP Task-3"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-4"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-5"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-6"], "PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task-7"],"PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else if Text.Contains([#"SAP Task -8"],"PIPING") and Text.Contains([#"SAP Task-2"], "INT") then "PIPING-INT" else "False")
Thanks
Lavdeep
Thanks Lavdeep,
Can we make it simpler similar to switch
Hi @Anonymous
Instead of creating a custom column in power query, you can create a calculated column in the data model (Data View) where you can use switch function