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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
o59393
Post Prodigy
Post Prodigy

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!

2 ACCEPTED SOLUTIONS
danextian
Super User
Super User

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





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

AllisonKennedy
Super User
Super User

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.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

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.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

danextian
Super User
Super User

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





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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