Solved

Average in a Query

Posted on 2007-03-21
6
254 Views
Last Modified: 2010-03-20
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?
0
Comment
Question by:thotovec
  • 3
  • 3
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18765744
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 Comment

by:thotovec
ID: 18766187
Need to specify . . . ?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18766234
what kind of database are you using?
I assume MS Access, but I want to avoid anyone guess around.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:thotovec
ID: 18767091
I'm sorry - MS Access 2003.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18767132
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
 

Author Comment

by:thotovec
ID: 18767437
Perfect!  Thank you!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now