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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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
Back
Top