Results 1 to 2 of 2
  1. #1
    wlanssens is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2013
    Posts
    10

    How to calculate a total of "0" when there is no data


    Hi,

    I'm trying to figure something out but it came to a point where I need some assistence because its getting hair pulling frustrating.

    Say I have a table with ID's of people and a column with the hours they need to work on a specific day.
    I want to make a query where I get the total working hours for every person in that table for a certain date.
    The problem is that when a specific person in the table has no hours for a certain day he doesn't show up in the query if I choose that day.., is there a way to make sure that I get everybody's names for every day even if they don't have any hours on that day, but instead of not showing it would show a "0" instead?

    thanks!

  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,646
    That requires a dataset of all possible people and date combinations. Try something like:

    Query1 - create a dataset of all dates in work hours table
    SELECT DISTINCT WorkDate FROM HoursTable;

    Query2 - create a dataset of all possible employee/date combinations by omitting join clause which produces a cartesian relation of records
    SELECT EmployeeID, WorkDate FROM Employees, Query1;

    Query3 - basically a find unmatched query and the query wizard can help with this
    SELECT Query2.*, HoursTable.*, Nz(WorkHours,0) AS HoursWorked FROM Query2 RIGHT JOIN HoursTable ON Query2.EmployeeID=HoursTable.EmployeeID AND Query2.WorkDate=HoursTable.WorkDate;

    I might be wrong about the RIGHT and maybe should be LEFT - always confuses me - use query builder. Want the join to 'Include all records from Query2 and only those from HoursTable that match'.
    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: 9
    Last Post: 08-19-2013, 03:00 PM
  2. Update "Total" Field on Form
    By dargo72 in forum Forms
    Replies: 2
    Last Post: 04-01-2013, 07:35 AM
  3. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  4. 2003 Query "Total" Missing in 2007
    By Buchal in forum Queries
    Replies: 3
    Last Post: 02-14-2012, 09:43 AM
  5. Replies: 7
    Last Post: 01-23-2011, 12:32 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