cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Switch true expression not working

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

sriram_harihara_0-1603854667473.png

 

 

1 ACCEPTED 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

View solution in original post

8 REPLIES 8
Community Support
Community Support

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.

Super User III
Super User III

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.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

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.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

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

View solution in original post

Anonymous
Not applicable

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 

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Wave Release 2

Check out the updates in Power BI.

Overview of Power BI 2020 release wave 2!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors