# Average in a Query

Hello Experts!

I am trying to calculate an average in a query, but I must be missing something in the syntax.

The table I'm working from has 7 columns - 1 "Name" column and 6 "Value" columns (V1, V2, etc).  Some of the value columns may be zero.  I have pulled all 7 columns into the query data fields.

My approach was to write an expression named "Average" in the 8th column in the query:
Average:  Avg([V1]+[V2]+[V3]+[V4]+[V5]+[V6])

Unfortunately, this simply sums the values.

Any ideas?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Billing EngineerCommented:
average function computes the average of all the grouped rows (if any).

in your case, you need to take the sum and divide by 6:
Average:  ([V1]+[V2]+[V3]+[V4]+[V5]+[V6])/6

if some values are zero, and you want to ignore them, you will have to "count" those.
however, there is no way of doing so that is works for all the databases with the same syntax, so you need to specify
0
Author Commented:
Need to specify . . . ?
0
Billing EngineerCommented:
what kind of database are you using?
I assume MS Access, but I want to avoid anyone guess around.
0
Author Commented:
I'm sorry - MS Access 2003.
0
Billing EngineerCommented:
Average:  ([V1]+[V2]+[V3]+[V4]+[V5]+[V6])/ (
IIF( ISNULL(V1), 0, 1)  + IIF( ISNULL(V2), 0, 1) + IIF( ISNULL(V3), 0, 1 )  +
IIF( ISNULL(V4), 0, 1)  + IIF( ISNULL(V5), 0, 1) + IIF( ISNULL(V6), 0, 1 )
)
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Perfect!  Thank you!
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.