Results 1 to 3 of 3
  1. #1
    mfred1 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    2

    Averaging fields with missing data

    I have a set of fields in a query for which I need to do an average for each entry. Let's say there are 5 fields. The issue is that not all 5 fields have data. So I cannot do ([Field1]+[Field2]+[Field3]+[Field4]+[Field5])/5. Any flank fields causes the average to be blank. Is there a way to create an average calculation in Access where blank fields are ignored?

  2. #2
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    It sounds like your Table might not be properly normalized. If you have control over the design of your Tables, you might want to look at coming up with a more normalized structure for them.

    That said...

    Code:
    IIf([Field1]+[Field2]+[Field3]+[Field4]+[Field5]>0,[Field1]+[Field2]+[Field3]+[Field4]+[Field5]/(IIf([Field1]>0,1,0)+IIf([Field2]>0,1,0)+IIf([Field3]>0,1,0)+IIf([Field4]>0,1,0)+IIf([Field5]>0,1,0)),0)
    Assuming all of your Columns (when non-0 and non-blank) will be positive numbers, this equation will check if at least one of the Columns has a number in it.
    • If not, then it just returns 0.
    • If so, it will add the 5 Columns together and then divide them by the number of non-0 Columns.

    If a Column can be completely blank, then you will need to wrap everything in Nz() Functions to force them to return 0 when empty.

    Code:
    IIf(Nz([Field1],0)+Nz([Field2],0)+Nz([Field3],0)+Nz([Field4],0)+Nz([Field5],0)>0,Nz([Field1],0)+Nz([Field2],0)+Nz([Field3],0)+Nz([Field4],0)+Nz([Field5],0)/(IIf(Nz([Field1],0)>0,1,0)+IIf(Nz([Field2],0)>0,1,0)+IIf(Nz([Field3],0)>0,1,0)+IIf(Nz([Field4],0)>0,1,0)+IIf(Nz([Field5],0)>0,1,0)),0)

  3. #3
    mfred1 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    2
    Thank you very much.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2015, 01:43 PM
  2. Replies: 0
    Last Post: 06-19-2014, 05:06 PM
  3. Missing data entry fields in my subform
    By Nashskye13 in forum Forms
    Replies: 7
    Last Post: 07-30-2012, 03:22 PM
  4. Missing data when adding contents of two fields
    By Jamescdawson in forum Forms
    Replies: 3
    Last Post: 03-08-2012, 09:39 AM
  5. Missing Fields Within a Report
    By genest11 in forum Reports
    Replies: 1
    Last Post: 10-05-2011, 11:13 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