Results 1 to 6 of 6
  1. #1
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35

    calculations

    Howdy folks,

    Hoping someone can help me with some calculations in a query

    I need to take sum and average data in one column based on values in 4 other other columns.

    The fields I have are as follows, and basically what the data looks like with the calculation I need to do:

    ProjectID....Space...Time...Date...........Number. ..Expr1


    1 ..............2 .........5pm....06/22/13.....2...........2.5
    1 ............. 2 .........5pm....06/22/13.....3...........2.5
    2...............5......... 3pm ...01/24/14.....8...........4.5
    2...............5..........3pm ...01/24/14.....1...........4.5
    3...............1..........6am....02/02/14.....10.........8.3
    3...............1..........6am....02/02/14.....6...........8.3
    3...............1..........6am....02/02/14.....9...........8.3

    So if ProjectID, Space, Time, and Date have equal values in multiple records, I need to sum the values in the field "Number" for those records, and then divide by the number of records, for the final values in Expr1.


    Hope someone can offer some insight into creating an expression for this.

    Cheers!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    SELECT * FROM <TABLENAME> GROUP BY ProjectID, Space, [Time], [Date], [Number]

    this is an aggregate query, it will give you one record for each combination of projectid, space, time and date field. As a side note, time, date and number are ALL reserved words in access which is why I put them in [] brackets. Don't use reserved words for field names, it only leads to aggravation.

    From here put in two new fields

    NumberAverage: number
    NumberSum: number

    in the TOTALS line of your aggregate query use the
    AVERAGE
    and
    SUM

    Functions respectively.

  3. #3
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35
    OK, awesome! I will give it a go and keep you posted.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    SELECT ProjectID, Space, [Time], [Date] FROM <TABLENAME> GROUP BY ProjectID, Space, [Time], [Date]

    I erred, your aggregate query should look like this first, then add the formulas (average and sum fields)

  5. #5
    frustratedwithaccess is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Posts
    35
    Ok... Thanks again for the help. It seems to be working!

    How do I mark a thread resolved?

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Do you really have field names "Space", "Time", "Date" & "Number"? These are reserved words in Access and shouldn't be used as object names. Plus they are not very descriptive.
    You will probably have lots of headaches with these field names.....

    See http://www.allenbrowne.com/AppIssueBadWord.html


    --------
    To mark solved, look for "Thread Tools" just above the first post (right hand side - in green bar).

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

Similar Threads

  1. Help with doing calculations in queries
    By DB88 in forum Access
    Replies: 3
    Last Post: 05-14-2014, 04:39 PM
  2. Payroll calculations
    By Rogue in forum Programming
    Replies: 5
    Last Post: 07-10-2013, 10:34 PM
  3. calculations
    By DariusD in forum Access
    Replies: 3
    Last Post: 01-01-2013, 07:22 PM
  4. calculations??
    By richrit in forum Access
    Replies: 1
    Last Post: 04-11-2012, 05:06 PM
  5. Budget Calculations
    By Arwa in forum Queries
    Replies: 4
    Last Post: 07-26-2011, 03:56 AM

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