Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access query syntax - division by zero in aggregate function

Posted on 2014-02-25
3
Medium Priority
?
875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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 52

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

610 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