# best practice for multiple if conditions

#### dickson30

##### New Member
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.

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.

#### VBA Geek

##### MrExcel MVP
you have some then with capital T

#### dickson30

##### New Member
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
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

Replies
0
Views
1K
Replies
2
Views
480
Replies
1
Views
451
Replies
1
Views
399
Replies
2
Views
191

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.

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.

### Which adblocker are you using?

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

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