best practice for multiple if conditions

dickson30

New Member
Joined
Oct 11, 2018
Messages
2
Hi hoping someone can help I've got multiple if statement which I would be fine writing in excel but struggling in powerquery (the below is not working expecting another then?!) would appreciate any help and what the best practice would be for the below and if anyone can make it work that would be great. Thank you.:confused:


= Table.AddColumn(#"Added Custom", "Custom",
each if [Adjust]="monkey"
then if[Pear]>0
then if[Banana]>0
then if [Apple]>0
then ([Banana]+[Pear]+[Apple])/3
else if [Apple Juice]<0
Then 0
else ([Pear]+[Banana])/2
else if [Apple]>0
then ([Pear]+[Apple])/2
else if [Banana Smoothie]>0
then [Pear]
else 0
else if [Banana]>0
Then if [Apple]>0
then if [pear juice]<0
then ([Banana]+[apple])/3
else [Banana]+[apple])/2
else if [pear juice]<0
then [Banana]/2
else [Banana]
else if [Apple]> 0
then if [Banana Smoothie]<0
then 0
else if [pear juice]<0
then [Apple]/2
else [Apple]
else 0
else 0)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

dickson30

New Member
Joined
Oct 11, 2018
Messages
2
Thank you I re went through the code there was also a couple of other minor mistakes but got it running, so now I just wonder is there a better way to write the query?
 

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
Thank you I re went through the code there was also a couple of other minor mistakes but got it running, so now I just wonder is there a better way to write the query?


It depends on your business logic, I have notices there are some ifs that can be grouped with 'and' conditions
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,971
Messages
5,767,389
Members
425,410
Latest member
SmittyT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top