Link to home
Start Free TrialLog in
Avatar of susantrider
susantrider

asked on

AVG() or SUM() in different fields with nulls

I have used Avg() to calculate the average of valus in a single field that may contain null values. Now I want to calculate the average of 5 values that are in different fields. It is possible that some of these values can be null and I will not want to include these in the average. In this case when I try to add the 5 values when one of them is null I come up with a null value. Can anyone help me wiht this? Thanks in advance.

Susan
Avatar of Simonac
Simonac

u can use IsNull(FIELD) to include it or not in the AVG(), something like:

For each field in fields
   if not IsNull(field)
      SUM = SUM + field
      intNbrValues = intNbrValues + 1
   end if
next

  AVG = SUM/intNbrValues
ASKER CERTIFIED SOLUTION
Avatar of paasky
paasky
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of susantrider

ASKER

Paasky, you have helped me agian. Thanks. The other answer was also helpful. Thank you!
Always happy to help you Susan. :o)

Best regards,
Paasky