If then Query

rowk

Board Regular
Joined
Aug 11, 2002
Messages
72
Hi there,

I have a pretty stupid question - brian is not working today.

I have a col that has # of eggs - I'm trying to write a query that will add a col with the following in it:
3 or less - "Group 1"
between 4 and 30 - "Group 2"
between 31 and 300 - "Group 3"
greater than 300 - "Group 4"

I think i'm just thinking about it too much.

Any help would be greatly appreciated.

Row
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Row

Try something like this :

Iif([Num_Eggs]<4, "Group 1", Iif([Num_Eggs]<31, "Group 2", Iif([Num_Eggs]<301, "Group 3", "Group 4")))

But remember to use your actual variable name where I have used [Num_Eggs]

HTH, Andrew. :)
 
Upvote 0
Thanks for that Andrew,

Will the formula you've given take into account the group two perameter being between 4 and 30 - or will it just take everything <31?

Eggs can be a messy business. :p
 
Upvote 0
Hi

Eggs can be a messy business.

I know - I used to work on a chicken farm many moons ago ..... it put me off eggs and chicken for about a year.....

Will the formula you've given take into account the group two perameter being between 4 and 30 - or will it just take everything <31?

The formula reads from left to right, for values less than 4 it will return "Group 1" and the <31 bit won't come into it and so on.

Give it a try - the worst that can happen is that it won't work - although it should. ;)

HTH, Andrew. :)
 
Upvote 0

Forum statistics

Threads
1,221,827
Messages
6,162,200
Members
451,753
Latest member
freddocp

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