473,396 Members | 2,018 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,396 software developers and data experts.

Need to Average Grand Total of 14 fields

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 follows:

=Sum([T1Number]) ... =Sum([T14Number])

Then I need to get an average of all fields as follows:

(Grand Total of all fields) / (# of fields where Sum of any field <>
0, or IS NOT NULL)

How can I do this?

Thank you for your help!

CSDunn
Nov 12 '05 #1
3 3225
CSDunn wrote:
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 follows:

=Sum([T1Number]) ... =Sum([T14Number])

Then I need to get an average of all fields as follows:

(Grand Total of all fields) / (# of fields where Sum of any field <>
0, or IS NOT NULL)

How can I do this?

Thank you for your help!

CSDunn


Not sure. But I would start off with creating a hidden field that is a
running sum incremented by 1 to get a list of the total record count.

Then I'd create 14 invisible fields that would increment by 1 for each
field value not zero maybe by useing a running sum.

At the end of the record those 14 fields not zero means they had a value
and you could average them.

Or....

You could create another query that uses the same filter and fields of
the report. Ex for column1
Col1 : IIF([Field1] > 0,1,0)
and once you have done that for all 14 fields, make the query a Totals
query and set the Totals row for each column to Sum. You might want to
incorporate the amounts so you have something to calculate on.

Now create a report using this query. THen open up the main report and
drop this report to print at the end.

In your main report, add a column to the recordsource. Ex: Master:"M"
Now make Master your first major group/sort and add a footer. Drop the
sub-report into the footer for Master.

I think this will be much easier to accomplish than a bunch of running sums.

Nov 12 '05 #2
CDB
This fairly screams "not-normalized repeating fields...". A normalized data
schema would allow a basic query to give you the answer.

One approach is to use a union query to convert the data into a normalised
form:

SELECT Table1.PK, Table1.T1Number from Table1 WHERE Table1.T1Number IS NOT
NULL
UNION ALL SELECT Table1.PK, Table1.T2Number from Table1 WHERE
Table1.T2Number IS NOT NULL
etc

Then use that query to source an aggregate query to get the grand total and
average.

Zero (0) is a value, and should be permitted only if it is the required
value - it ought not to be used to mean "no value".

(6 salesmen, 15 units sold: average units per salesman: 2.5, even tho' 1
salesman sold none.)

Clive
"CSDunn" <cd***@valverde.edu> wrote in message
news:80**************************@posting.google.c om...
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 follows:

=Sum([T1Number]) ... =Sum([T14Number])

Then I need to get an average of all fields as follows:

(Grand Total of all fields) / (# of fields where Sum of any field <>
0, or IS NOT NULL)

How can I do this?

Thank you for your help!

CSDunn

Nov 12 '05 #3
Thanks for your help. One thing I am going to try looks something like this:

Option Explicit
Option Compare Text
Private Sub PageFooter_Format(ByRef intCancel As Integer, _
ByRef intFormatCount As Integer)

Dim lngCount As Long
Dim lngNumFields As Long
Dim dblTotal As Double
Dim strFieldName As String

For lngCount = 1 To 14
' strFieldName = "T" & CStr(lngCount) & "Number" ' To sum Fields
' XOR
' strFieldName = "txtT" & CStr(lngCount) & "Number" ' To sum Controls
dblTotal = dblTotal + Nz(Me(strFieldName), 0)
lngNumFields = lngNumFields + IIf(Nz(Me(strFieldName), 0) = 0, 0, 1)
Next lngCount

If lngNumFields > 0 Then
Me.txtTotal = dblTotal / lngNumFields
Else
Me.txtTotal = 0
End If

End Sub
**********************

CSDunn
Salad <oi*@vinegar.com> wrote in message news:<LC******************@newsread2.news.pas.eart hlink.net>...
CSDunn wrote:
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 follows:

=Sum([T1Number]) ... =Sum([T14Number])

Then I need to get an average of all fields as follows:

(Grand Total of all fields) / (# of fields where Sum of any field <>
0, or IS NOT NULL)

How can I do this?

Thank you for your help!

CSDunn


Not sure. But I would start off with creating a hidden field that is a
running sum incremented by 1 to get a list of the total record count.

Then I'd create 14 invisible fields that would increment by 1 for each
field value not zero maybe by useing a running sum.

At the end of the record those 14 fields not zero means they had a value
and you could average them.

Or....

You could create another query that uses the same filter and fields of
the report. Ex for column1
Col1 : IIF([Field1] > 0,1,0)
and once you have done that for all 14 fields, make the query a Totals
query and set the Totals row for each column to Sum. You might want to
incorporate the amounts so you have something to calculate on.

Now create a report using this query. THen open up the main report and
drop this report to print at the end.

In your main report, add a column to the recordsource. Ex: Master:"M"
Now make Master your first major group/sort and add a footer. Drop the
sub-report into the footer for Master.

I think this will be much easier to accomplish than a bunch of running sums.

Nov 12 '05 #4

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

Similar topics

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...
3
by: Tony Lennard | last post by:
I have several queries, which generate about 10 fields each a text field of length 2 (which contain effort and attainment grades), eg A2, B4, A3, A3. I am trying to calculate an 11th fields, which...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
2
by: Jerry | last post by:
Hi, I found an interesting article on running totals at http://www.databasejournal.com/features/mssql/article.php/3112381. I have converted one to postgresql for my banking account: --...
8
by: wastedhello | last post by:
ok. here are a list of things i cant fix. ive been trying for way to long now. 1. if more then 1000 values are told, will still continue with program. 2. if -max, min, average etc run, and 2...
4
by: marylove2007 | last post by:
Help Plzzzz!!!!!!!!!!!!!!!!!!!... > A palindrome is a number or a text phrase that reads the same backward and forward. For example, each of the following five-digit integers is a palindrome: 12321,...
0
by: jessicaeatworld | last post by:
Hi, I'm using Access 2003 on Windows XP. I have created a PivotTable View Form and at the bottom is an automatically inserted Grand Total row. I added sum and avg fields and then hid the details so...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
3
by: kkshansid | last post by:
how to get grand total of two years 2001,2002 are fields SELECT sum( 2001 ) AS "2001-2002", sum( 2002 ) AS "2002-2003", ( "2001-2002" + "2002-2003" ) AS "grand total" FROM school this query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.