mathematical function

Excellent1

New Member
Joined
Oct 14, 2002
Messages
41
I am working with a table in Access that contains

Tracking number, invoice number, customer number, box
number, freight charge, ship via rate. we have two
customers ABC001 and DEF002 that have special freight
charge rules. for ABC001 their freight charge is 4.50
less than the value in freight charge and for DEF002
their freight charge is 2.50 less than the value in
freight charge. How can I code a function to pass
through access and make these changes for the given
customers? thank you in advance :)
 
khexcel said:
Since you have two iif, you need two closing parenthesis at the end.

Code:
[FreightCharge]iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge))

I just got the same error
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I changed it to this
Code:
iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge))

and wasn't prompted with an error.......but, the query doesn't appear to work...I get a type conversion failure for all records
 
Upvote 0
Instead of...
Code:
[FreightCharge]iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge)
Try...
Code:
Freight:iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge))
You need the colon instead of square brackets before the first IIF.
Denis
 
Upvote 0
Also, if CustomerNumber truly IS a number, you can't filter it using text. You will have to filter on the field that contains the values "BAT0002", etc.

Denis
 
Upvote 0
I used

Code:
Freight:iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge))

and I got an error saying there is an invalid .(dot) ! or invalid parentheses.

CustomerNumber is actually a text field "BAT002" is text
 
Upvote 0
This is weird, but try changing
Code:
Freight:iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge-2.5, 
FreightCharge))
to
Code:
Freight:iif(CustomerNumber = "BAT002",FreightCharge - 4.5, 
iif(CustomerNumber = "ODO001",FreightCharge - 2.5, 
FreightCharge))
Access may not be seeing the second expression correctly because no gaps. Otherwise, back to my earlier comment. CustomerNo is a NUMBER, you say. Why are you using TEXT to filter it? Access will spit the dummy.

Denis
 
Upvote 0
freightcharge is a number, not customernumber

and I still get the same error after changing the spacing, it highlights the first (
 
Upvote 0
In Access control source, you have to surround the fields with []. Try This:

Freight:iif([customerNumber]= "BAT002",[freightCharge] - 4.5,
iif([CustomerNumber] = "ODO001",[FreightCharge]-2.5,
[FreightCharge]))

To my previous posting, if you are placing this formula in the "update to"
section of an update query do not include "Freight:" before the formula.
First select the field you want to update, in this example Freightcharge
then try this formula:

=iif([customerNumber]= "BAT002",[freightCharge] - 4.5,
iif([CustomerNumber] = "ODO001",[FreightCharge]-2.5,
[FreightCharge]))
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,327
Members
451,697
Latest member
pedroDH

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