Using IIF to divide even when the denominator is 0.

dickpierce

Board Regular
Joined
Nov 26, 2004
Messages
148
Office Version
  1. 2007
Platform
  1. Windows
I'm an Access newbie. I have Access 97 and I'm trying to calculate batting averages, using a query field. Unfortunately, some of the denominators in my data table are either blank or have a zero. I would like a formula that would let me divide Hits by At Bats without getting an error message. My criteria field is set to have a greater than or equal to .300 value. Can anyone help? :confused:
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about this expression?

BattingAverage:Iif([AtBats]<>0, [Hits]/[AtBats], 0)

Change the field names as necessary.
 
Upvote 0
Thanks for replying, but nope your formula didn't work. Also, I neglected to mention that the sum of Hits divides the sum of At Bats.
 
Upvote 0
When you say the formula didn't work what exactly do you mean?

Did it cause errors or not return the expected result?

In your original post (OP) you said:
divide Hits by At Bats
Perhaps this will work:

BattingAverage:Iif([Hits]<>0, [AtBats]/[Hits], 0)
 
Upvote 0
Aha! It worked! Thanl you! Now I have another problem. I would like to add the sum 6 columns in which 4 of the columns contain no data. I know that I must use IsNull, but I can't seem to get it to work. Thanks
 
Upvote 0
Norie! Your first formula worked, however, my fat fingers mistyped.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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