Results 1 to 6 of 6
  1. #1
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9

    Show 0 for no record in field

    Hi

    I want to show zero against a date if it has no record in the query

    For example I spend money on the first 5 days of the month but then save for the rest of the month and spend no further money, I would want to see the amount i spent against those days but then 0 against the remaining dates in the month

    I have a table and a query, table has every date for the next 10 years in and the query has the data showing what cost I have spent for days with a record

    The SQL is below

    SELECT Tbl_Dates.Dates, Qry_Cells_CON_KPI_Daily_Cost.Value


    FROM Tbl_Dates INNER JOIN Qry_Cells_CON_KPI_Daily_Cost ON Tbl_Dates.Dates = Qry_Cells_CON_KPI_Daily_Cost.Date_Raised
    GROUP BY Tbl_Dates.Dates, Qry_Cells_CON_KPI_Daily_Cost.Value;

    I know it is something simple that I have to put in the code above but cant figure it out lol

    Thanks in advance

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Assuming that daily cost is the figure you are looking for then replace this line with this using the Nz() function

    Code:
    SELECT Tbl_Dates.Dates, Nz(Qry_Cells_CON_KPI_Daily_Cost.Value,0) 


    However you are also grouping this data without doing any aggregate (Sum, count, etc) functions, which seems a bit strange...
    Also Value is a reserved word in Access so not a great choice of field name - Amount or CostValue would better, as that will trip you up later.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try this:
    Code:
    SELECT Tbl_Dates.Dates, Nz(Qry_Cells_CON_KPI_Daily_Cost.Value,0)+0
    FROM Tbl_Dates LEFT JOIN Qry_Cells_CON_KPI_Daily_Cost ON Tbl_Dates.Dates = Qry_Cells_CON_KPI_Daily_Cost.Date_Raised
    GROUP BY Tbl_Dates.Dates, Nz(Qry_Cells_CON_KPI_Daily_Cost.Value,0)+0;

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    However you are also grouping this data without doing any aggregate (Sum, count, etc) functions, which seems a bit strange...
    Also Value is a reserved word in Access so not a great choice of field name - Amount or CostValue would better, as that will trip you up later.
    Minty,
    They will also need to change their Join type to a LEFT JOIN, instead of an INNER JOIN, like I showed above.

  5. #5
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9
    Thankyou guys for reply

    Used JoeM example and worked spot on

    didnt realize i had group by on so have removed and changed name as advised, thanks Minty

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome. Glad it all worked out for you.

    Yes, I thought the Group By bit was a bit odd, unless you had duplicate records in your table that you were trying to get out of the results (or if you were trying to Sum by day, in which case you would group on date and SUM the amount field).

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

Similar Threads

  1. Replies: 2
    Last Post: 04-19-2018, 03:51 PM
  2. Replies: 2
    Last Post: 03-14-2017, 02:48 AM
  3. Replies: 3
    Last Post: 07-20-2014, 08:56 PM
  4. Replies: 4
    Last Post: 04-03-2014, 08:03 AM
  5. Replies: 1
    Last Post: 12-02-2011, 09: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