Results 1 to 10 of 10
  1. #1
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286

    Query to show AVERAGE of all values in a field


    Hello, how do i create a query that will take all the values in a column and divide it by every row in the table? thanks!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    SELECT Avg(TableName.FieldName) AS Average
    FROM TableName;

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Something like the following should work, or at least get you started

    select SumOfAmount/CountOfId as Aver_age
    FROM
    (SELECT Sum(Grades.Amount) AS SumOfAmount, Count(Grades.id) AS CountOfid
    FROM Grades);

    In my sample SUM(Grades.Amount) represents the summing all values in a column.
    Count(Grades.id) represents the number or rows in the table.

    good luck

    oops I see Robeen has responded while I was typing.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    sorry . . . Orange has a more accurate solution.

    Mine will only be correct if every row in the table always has a value in the field you need to average.

  5. #5
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    hello, im not too familliar with the SQL view, can you guys help me with putting this in Design View where it shows the table and such?

    for example, what do i put in the "field" box or "criteria" box?

    currently, my query spits out a table. i just want one column to display the average of the values in the "days late" column in that table. thanks!

  6. #6
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    i tried the SQL view and this is what i have:

    SELECT Sum(tblHHFRequest_Main.Days_Late) AS SumOfAmount, Count(tblHHFRequest_Main.Channel_ID) AS CountOfid
    FROM tblHHFRequest_Main;


    when i run it, a box appears saying "enter parameter value" for tblHHFRequest_Main.Days_Late

  7. #7
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    The 'enter parameter value' message - if you didn't create a 'Parameter Query' has usually meant [for me] that I have had a table name or field name in my query that doesn't exactly match a table name or field name in my database.

    The SQL that you posted doesn't do any Averaging. It does one 'Sum' and one 'Count'.

    Have you tried the suggestion that I posted earlier?
    Try it and see if it gives you what you need.
    If it does not, then you can pursue what Orange suggested.

    Let us know how you fare.

  8. #8
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    thank you, that worked.

    also, i have a report that has a record source of a seperate query. The average query above will spit out only 1 value. Is it display the result of this query above onto my report who's record source if from another query? thanks!

  9. #9
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    What you might be able to do for your report is this:
    Create a third query that combines the data from the query that currently feeds the report, and your Average query:
    In design mode select both queries as your data source.
    Pull in all the fields from your report query and also the Average field from your average query.
    Save the new query.
    Open the report in design view and go to the Data tab and change the Record Source to your newly created query.
    Then use the 'Add Existing Fields' to add your average field to the report.
    Remember - there is only one Average value from your average query.

    Hope this helps!

  10. #10
    taimysho0 is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Nov 2011
    Posts
    286
    I see, thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combobox to show two field values
    By lnordstrom in forum Forms
    Replies: 2
    Last Post: 03-30-2011, 12:33 PM
  2. Average unbound values?
    By C90RanMan in forum Forms
    Replies: 15
    Last Post: 07-29-2010, 06:57 AM
  3. query to show gaps in a date field
    By Lockrin in forum Database Design
    Replies: 1
    Last Post: 05-28-2010, 10:48 AM
  4. Replies: 2
    Last Post: 09-26-2009, 07:19 AM
  5. Replies: 1
    Last Post: 03-15-2007, 03:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums