+ Reply to Thread
Results 1 to 8 of 8

Query to calculate averages with criteria

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Query to calculate averages with criteria

    I am new to using Queries in Access and need some guidance on how to simulate/convert code that I have written in Excel VBA to Access Queries.


    I have a list of Course Codes (Columns A) and dates (Column B) in an Excel worksheet.
    I run a select query on my access database to get the averages using this code in Excel VBA:
    The result is the average grade by Course Code for the last 12 months
    Please Login or Register  to view this content.
    If I use this SQL code in an Access Query I get the averages on ALL values in my database.

    Please Login or Register  to view this content.
    My Excel VBA code allows me to reference each Course Code and corresponding date by values in a worksheet.

    My research suggests that I am looking for something like Union ALL but my SQL coding is very limited so I haven't been able to solve my problem.

    Any guidance on how I can adapt the Access Query code to simulate the Excel VBA code?
    Last edited by anrichards22; 07-16-2016 at 06:39 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Query to calculate averages with criteria

    Why aren't you using the date part of the criteria in the Access query?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Query to calculate averages with criteria

    Norie,
    I was not sure how to incorporate the date into my Access query.
    I have attempted to incorporate the date into my query but I do not get the result I want.
    I end up with the query calculating the average grade for each date & Course Code combination, like this:

    25/02/2016 ACCT1 35.40
    24/03/2016 ACCT1 36.80
    23/04/2016 ACCT1 37.50


    I have also tried using Top 100/200/300/400 but I can't get that to work either.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Query to calculate averages with criteria

    How do you want to group the dates?

  5. #5
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Query to calculate averages with criteria

    For each date I want to calculate the average Grade for the previous 12 months.

    For example:
    If the Course Code is ACCT1 and the date is 25/02/2016 then I want to calculate the average for ACCT1 for the period 25/02/2015 to 24/02/2016
    If the Course Code is ACCT1 and the date is 25/05/2016 then I want to calculate the average for ACCT1 for the period 25/05/2015 to 24/05/2016
    etc

    Each Course Code has multiple dates. Each Course Code can have multiple entries on the same date.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Query to calculate averages with criteria

    Is the date criteria based on the current date?

  7. #7
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Query to calculate averages with criteria

    No.

    I am trying to get a moving average at each data point.

  8. #8
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Query to calculate averages with criteria

    Any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Please help - calculate weekly averages (many criteria)
    By collegeitdept in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-09-2014, 03:38 PM
  2. [SOLVED] Days360 and Auto Calculate Averages with Criteria
    By tskabo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-05-2012, 08:53 PM
  3. Calculate Averages
    By N0b0dyzAngel in forum Excel General
    Replies: 8
    Last Post: 07-06-2010, 01:50 PM
  4. Replies: 1
    Last Post: 05-02-2008, 10:41 AM
  5. Calculate averages
    By MagicMan0027 in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 04-27-2008, 02:49 PM
  6. calculate averages
    By inspiredtoo in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-29-2006, 06:30 PM
  7. calculate averages
    By MR1 in forum Excel General
    Replies: 1
    Last Post: 05-10-2006, 05:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1