Avatar of kateebebe
kateebebeFlag for United States of America

asked on 

Division by Zero

I'm getting a Division by zero error with the following expression:
Attach Pct: Avg(((([Layer Attachment]/[Layer IRO Percent])/[TIV])*100))


I have tried the IIF but can't seem to get it to work.  
Microsoft Access

Avatar of undefined
Last Comment
Rey Obrero (Capricorn1)
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


use the iif this way

iif([field1]=0,0,[Field2]/[Field1])
Avatar of kateebebe
kateebebe
Flag of United States of America image

ASKER

iif([LAYER IRO PERCENT]=0,0,Avg(((([Layer Attachment]/[Layer IRO Percent])/[TIV])*100)))

Its not working for me.  
<No points wanted>

Capricorns post basically says that you should do the "=0" for any/all fields that may be zero
...so you have to adjust your syntax accordingly.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Depends on what you want to substitute for sero, but try this:

iif([Layer Attachment] = 0 OR [Layer IRO Percent] = 0, 0, Avg(((([Layer Attachment]/[Layer IRO Percent])/[TIV])*100)))
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Got the fieldnames wrong in my earlier post above, but as pointed out by the others, you need to handle fields that can result in zeros in the denominator(s) :

iif([TIV] = 0 OR [Layer IRO Percent] = 0, 0, Avg(((([Layer Attachment]/[Layer IRO Percent])/[TIV])*100)))
Avatar of kateebebe
kateebebe
Flag of United States of America image

ASKER

I get the error you tried to execute a query that does not include the specified expression as part of an aggregate function.
Avatar of mbizup
mbizup
Flag of Kazakhstan image

>> you have to place the "avg" outside of the iif

Good point!  :)
kateebebe,

did you try the post at http:#a36917561 ?
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo