Forum Discussion

o59393's avatar
o59393
Post 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" else 
if [#"[ Container Material ]"] = "Glass" then "GLASS"
if [#"[ Container Material ]"] = "Aluminium" then "CAN"
if [#"[ Container Material ]"] = "Flexible Laminate" then "TETRA" 
else null

 

 

But if do 2 I get no error:

 

How can I ger right the first image ?


Thanks!

  • 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

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

2 Replies

  • 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
    AllisonKennedy
    Community Champion
    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.