473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Return average of non zero values in query

How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...
Nov 13 '05 #1
5 7319
Could you base your average on the values returned by a query which selects
only values > 0?
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:06*****************@newssvr33.news.prodigy.co m...
How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...

Nov 13 '05 #2

"Squirrel" <wi*****@covad.net> wrote in message
news:7e**************************@msgid.meganewsse rvers.com...
Could you base your average on the values returned by a query which selects only values > 0?
The report is based on a query that computes Count and Avg on about 40
different fields. The query needs to return all of the records because it
might have a zero value in one field and an actual value in another.

The data is survey returns. Each field will have a value of 1 to 7, but can
be 0 (did not answer). I need to ignore the zero entries in getting the
counts and averages.

Randy
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:06*****************@newssvr33.news.prodigy.co m...
How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...


Nov 13 '05 #3

"Randy Harris" <ra***@SpamFree.com> escreveu na mensagem
news:K2*****************@newssvr17.news.prodigy.co m...

"Squirrel" <wi*****@covad.net> wrote in message
news:7e**************************@msgid.meganewsse rvers.com...
Could you base your average on the values returned by a query which selects
only values > 0?


The report is based on a query that computes Count and Avg on about 40
different fields. The query needs to return all of the records because it
might have a zero value in one field and an actual value in another.

The data is survey returns. Each field will have a value of 1 to 7, but

can be 0 (did not answer). I need to ignore the zero entries in getting the
counts and averages.

Randy
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:06*****************@newssvr33.news.prodigy.co m...
How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...


Hi,

just a thought:

SELECT Sum(field) / -Sum(field <> 0 ) as myAVG
FROM table;

bob

Nov 13 '05 #4
Hi,
The only way I could figure out how to do this was to run 1 query:
SELECT ur_table.*
FROM ur_table
WHERE (((ur_table.ur_field)<>0));

and then run a second query using the first query as the source:

SELECT Avg(Query1.ur_field) AS AvgOfur_field
FROM Query1;

There maybe a better way of doing this which others may point out but thats the best I could come up with :o)

Mark
"Randy Harris" <ra***@SpamFree.com> wrote in message news:06*****************@newssvr33.news.prodigy.co m...
How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...
Nov 13 '05 #5
Randy Harris wrote:
How can I report an average of non zero values?

If the values are:

5, 0, 6, 0, 4

I would like the result 5 (15 / 3), not 3 (15 / 5)

Thanks for any help...


(f1+f2+f3+f4+f5) / ((f1>0+f2>0+f3>0+f4>0+f5>0)*-1)

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PeterHardy | last post by:
I'm trying to work out an average field on a report that i'm writing and having the problem described below. e.g. if you had 3 weeks of cash which were 0, 2, 4 then a normal average would be...
5
by: Stephen Miller | last post by:
Hi, I am trying to add a staggered running total and average to a query returning quarterly CPI data. I need to add 4 quarterly data points together to calculate a moving 12-month sum (YrCPI),...
2
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I...
3
by: CSDunn | last post by:
Hello, I have 14 fields on a report that hold integer values. The field names use the following naming convention: T1Number, T2Number ....T14Number. I need to get a 'sub total' of all fields as...
4
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count...
0
by: Gary Carson | last post by:
Can anyone tell why the query below would throw a divide-by-zero error? The only reason I can see for the error happening would be if SUM() came out to be zero, but this never happens with the...
4
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a...
40
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost...
10
by: Toby Gallier | last post by:
Hello! I have a form that is calculating averages as follows: " =(NZ()+Nz()+Nz())/3 " However I need to now adjust for null values , so for example if value2 is null I would then need to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.