Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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

 

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    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

8 Replies

  • 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.

    • Anonymous's avatar
      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"

      • PhilipTreacy's avatar
        PhilipTreacy
        Super User

        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.

  • v-alq-msft's avatar
    v-alq-msft
    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.