Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

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
v-alq-msft
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.

PhilipTreacy
Super User
Super User

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors