Results 1 to 4 of 4
  1. #1
    hoachen is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17

    Sum of hours by year


    I have a table contain columns a long Date (Saturday, 02 August, 2014) and hours.

    My query is to sum only those in year after 2013, but query on sum up all. I have tried below:

    Total Days Taken: Sum(IIf([Date]>2013 and [Hours]<0,[Hours],0)/-8)


    Please help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Is the date field actually a date/time type? Regardless of the format setting on a date/time field, the actually value is unchanged.

    Why don't you just apply a filter to exclude all records prior to 2014? If you use an aggregate function in query the query must be a TOTALS (GROUP BY) query. Post the SQL statement for analysis.

    Consider building a report and use report Grouping & Sorting features. This will allow display of detail records and summary calcs.

    Date is a reserved word and should not use reserved words as names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    hoachen is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    17
    Thanks for your reply.
    Here is my sql query. If i add a column for the year, it will show all the rows instead of group by the member.

    SELECT [Member - vacation].Name, Sum([Member - vacation].Hours) AS [Total Hours Remain], Sum([Hours]/8) AS [Total Days Remain], Sum(IIf([Hours]<0,[Hours],0)/-8) AS [Total Days Taken]
    FROM [Member - vacation]
    GROUP BY [Member - vacation].Name;

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try:

    SELECT [Member - vacation].Name, Sum([Member - vacation].Hours) AS [Total Hours Remain], Sum([Hours]/8) AS [Total Days Remain], Sum(IIf([Hours]<0,[Hours],0)/-8) AS [Total Days Taken]
    FROM [Member - vacation]
    WHERE Year([Date])=2014
    GROUP BY [Member - vacation].Name;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-25-2014, 11:33 PM
  2. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  3. Replies: 1
    Last Post: 08-08-2012, 01:42 PM
  4. Replies: 4
    Last Post: 08-06-2012, 10:25 AM
  5. Replies: 4
    Last Post: 01-10-2012, 06:26 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