Solved

Access query syntax - division by zero in aggregate function

Posted on 2014-02-25
3
780 Views
Last Modified: 2014-02-25
Dear experts -
hopefully an easy one.
I am calculate an average using the formula below - which works well, however i want to avoid division by zero, which is giving me a #Num! error for certain results.

Any suggestions?
Thanks!

TR_Reg: Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,[e].[billrate],0))/Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,1,0))

Open in new window

0
Comment
Question by:terpsichore
3 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39885125
Hi,

Maybe

TR_Reg: Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,[e].[billrate],0))/IIF(Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,1,0))=0,null,Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,1,0)))

Open in new window

Regards
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39885126
This is one method, to first check if the sum is zero:

TR_Reg:
IIf(Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,1,0))=0, 0,
Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,[e].[billrate],0))/Sum(IIf([e].[billunit]=1 And [e].[volumeunit]=1 And [accounts].[regulatory]=True And [e].[action_ID]=38,1,0)))

/gustav
0
 

Author Closing Comment

by:terpsichore
ID: 39885144
This worked - thank you.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now