Results 1 to 6 of 6
  1. #1
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43

    #num! when divide by 0 like to display 0

    Hey all,

    I wrote the below formula which works like a charm unless its 0 divide by 0 which happens.

    =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]="02" And [Location]="Purple",1,0))/Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0))

    I have been researching and tried a couple of different things IIF(ISerror ....IIF(NZ.. few other things but I keep getting all different type of errors.

    Been struggling last couple of hours so now seeking help.



    As always thanks for your time and help.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe try:
    Code:
    =Sum(IIf([Pass or Fail]="Pass" And [Pay Period]="02" And [Location]="Purple",1,0))/IIf(Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)) = 0, 1, Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)))

  3. #3
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    ! it works, I understand the first 2 sums, what is that 3rd one doing that is making it = 0? after the dividing recheck it?...just trying to understand the workings.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The Numerator is OK, it can be zero.
    But the Denominator cannot be zero. So add an IIf() function; if the Denominator is zero, change it to 1.

    The IIF() function syntax is

    Code:
    IIf(exprtruepartfalsepart
    Breaking the statement apart, the Denominator is
    IIf(Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)) = 0, 1, Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)))

    IIf(
    expr : Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0)) = 0
    ,
    truepart : 1
    ,
    falsepart : Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0))
    )

    Reading this, it says :
    If the expression is equal to zero, return a 1 (the truepart) ELSE return the result of the calculation "Sum(IIf([Pay Period]="02" And [Location]="Purple",1,0))" (the falsepart)

    The Denominator will be the result of the calculation OR will be 1 (if the calculation is zero).

  5. #5
    tareyj8569 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Aug 2009
    Posts
    43
    Thank you for taking the time to break it down for me.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    No problem..happy to help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Divide report into four different areas
    By MyPaynes in forum Reports
    Replies: 1
    Last Post: 04-24-2014, 03:06 PM
  2. divide by zero
    By rbee in forum Access
    Replies: 11
    Last Post: 07-19-2012, 12:55 PM
  3. divide value by a constant and populate same field
    By ridgeview80 in forum Queries
    Replies: 5
    Last Post: 05-28-2012, 09:37 AM
  4. Replies: 0
    Last Post: 03-18-2010, 01:31 PM
  5. Replies: 1
    Last Post: 04-09-2009, 09:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums