Forum Discussion

o59393's avatar
o59393
Icon for Post Prodigy rankPost Prodigy
6 years ago
Solved

Nested if with power query

Hi all   I am doing nested ifs with power query, is there a limit for 2 if statements? I am getting an error when i do more than 2:       if [#"[ Container Material ]"] = "Plastic" then "PET" ...
  • danextian's avatar
    6 years ago

    Hi o59393 ,

     

    I am not sure what you are trying to achieve but your syntax is incorrect. I've typed in bold the missing part in the below formula:


    if [#"[ Container Material ]"] = "Plastic" then "PET" else
    if [#"[ Container Material ]"] = "Glass" then "GLASS" else
    if [#"[ Container Material ]"] = "Aluminium" then "CAN" else
    if [#"[ Container Material ]"] = "Flexible Laminate" then "TETRA"
    else null

  • AllisonKennedy's avatar
    6 years ago
    As danextian mentioned, you're missing a couple of 'else' statements in your syntax.

    You could do this using the 'Conditional Column' button from the 'Add Column' tab in the ribbon, and just click 'Add clause' until you are done. This makes it easier as Excel will take care of the syntax for you and you just need to worry about the correct order and values.