Query calcualtion not calculating for empty fields

kellem80

Board Regular
Joined
Apr 2, 2008
Messages
95
Hi, I'm working in Access 2007 and have a query that bring in fields A, B, C & D, all formatted as currency. I added an expression to subtract B, C & D from A. This only work if ALL THREE (B, C & D) have amounts entered (sometimes all 3 do, more than often only one or none have amounts). The calculation is not returning the amount of field A in the expression field when B, C, & D are blank, nor is it calulating if there is an amount in just one of the three. I have typed the expression freehand and used the expression builder, same result.

I am at a loss. I have tried this both in a Report (first) and as a query (second figuring I could base the report on the Query).

Any help or insight would be appreciated!
thanks!

(Oh, how I miss excel!)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
OK, a minute after posting I learned about Nz!
For anybody else having such an issue- type Nz before each portion of the expression that may have null (empty) values. ex:
=Nz([Inventory])-Nz([Sales])+Nz([Returns])

This will subtract any sales out of inventory and add back any returns, regarless if there were any sales or any returns!!

(I still miss excel!)
 
Upvote 0
Note that NZ has a second argument to it (basically, what to return in the event of a Null value). Normally, I would write your equation a little more explicitly like this:
Code:
[COLOR=#333333]=Nz([Inventory],0)-Nz([Sales],0)+Nz([Returns],0)[/COLOR]
It is probably defaulting to zero, so it works OK in your case as you have written it.

I just want to make you aware of that, because NZ can also be used on Text fields, i.e.
Code:
=NZ([Marital_Status],"Unknown")

Also note that NZ returns a text value. However, including it in mathematical functions coerces it to a numeric result. However, if you are just returning a single number, you may need to explicitly coerce it to a number by applying a basic math function to it (like adding zero) to avoid some funny behavior (depending on how it is being used afterwards), i.e.
Code:
=NZ([Sales],0) + 0
 
Upvote 0
Thank you. That was not included in the explanation I found. I suppose as time goes on and the data may be used differently that it makes good sense to include to avoid errors.
 
Upvote 0

Forum statistics

Threads
1,216,179
Messages
6,129,334
Members
449,503
Latest member
glennfandango

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