If statement in a query?

afs24

Board Regular
Joined
Sep 26, 2002
Messages
237
How do I write the following statement given this scenario?

If the feild WORK FUNCTION is equal to CARTPICK then I want to divide the feild CARTONS by HOURS. If the feild WORK FUNCTION is equal to FULLPICK then I want to divide the feild TRANS by HOURS. If WORK FUNCTION equals neither then I want it to be zero. So it should look something like this, I think:

CPH:if([WORK FUNCTION]=CARTPICK,"[CARTONS]/[HOURS]",IF([WORKFUNCTION]=FULLPICK,"[TRANS]/[HOURS]",""))

Is this correct???
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You need to use Iif in Access instead of If. (Stands for Immediate If)

Something like this:

CPH: Iif([WORK FUNCTION]=CARTPICK,[CARTONS]/[HOURS],Iif([WORKFUNCTION]=FULLPICK,[TRANS]/[HOURS],0))

I changed your "" to 0, since you said you wanted it to return zero. "" returns a zero-length string.

Hope it works.
 
Upvote 0
Any idea why the query asks me to enter CARTPICK, WORK FUNCTION, & FULL PICK in a pop up when I run the query?
 
Upvote 0
I assumed those are all fields in your query. It's having trouble finding them. Are they all spelled correctly? I notice now that in one place you have [Work Function] and in the other you have [WorkFunction] (no space). Which one is the correct one?
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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