Results 1 to 7 of 7
  1. #1
    janmack79 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    30

    Sum with Null Values

    I am trying to do a calculated field in a query to sum up three fields and below is my formula. However if there are nulls in any of the three field then it does not return a value. I read that you should put like NZ in front of each field in the calculation but that just returned an error message for me. Can someone advise what I would need to do to this formula to ignore a null value and sum up the other fields?



    Contract Value Calc: [Reports]![Value]+[Reports]![Services]+[Reports]![Maintenance]

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Should be nz([reports]![value],0) + nz(and so on...
    what error you getting?


    Sent from my iPhone using Tapatalk

  3. #3
    janmack79 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    30
    OK that worked perfect, thanks you!!

  4. #4
    Neil Bingham is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2009
    Location
    Cumbria UK
    Posts
    14
    Quote Originally Posted by janmack79 View Post
    I am trying to do a calculated field in a query to sum up three fields and below is my formula. However if there are nulls in any of the three field then it does not return a value. I read that you should put like NZ in front of each field in the calculation but that just returned an error message for me. Can someone advise what I would need to do to this formula to ignore a null value and sum up the other fields?

    Contract Value Calc: [Reports]![Value]+[Reports]![Services]+[Reports]![Maintenance]


    Suggest you change default value (in table design view select field then change to default to 0 in box at bottom) of all the relevant number fields in your table to 0 (zero) then no problem with the arithmetic whatever reports, forms or queries now or in future. Null is not the same as 0 so cannot be used in arithmetic and computers have prob with doing sums with blank fields also!

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Null means the value is unknown. Zero means zero (not Null and not Nothing). Thus zero is not Null. The suggestion may be appropriate for the particular database, but the two (0 and Null) should not be interchanged arbitrarily.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Neil Bingham is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2009
    Location
    Cumbria UK
    Posts
    14

    Null

    Quote Originally Posted by janmack79 View Post
    I am trying to do a calculated field in a query to sum up three fields and below is my formula. However if there are nulls in any of the three field then it does not return a value. I read that you should put like NZ in front of each field in the calculation but that just returned an error message for me. Can someone advise what I would need to do to this formula to ignore a null value and sum up the other fields?

    Contract Value Calc: [Reports]![Value]+[Reports]![Services]+[Reports]![Maintenance]
    Further my suggestion that you have default val as 0 in tables - you may need to do an update query to ensure all value fields in table are set to 0 (as I dont think - but haven't tested it - that it is retrospective if you change a field default)
    Appreciate that now your forms and reports will show 0 instead of being blank - BUT totals will be correct. If you do not want to show the 0 values then use Conditional Formatting on the fields in the reports or forms that you do not want the 0's to show (an Expr such as [Field]=0) - if condition is met then font colour to be set to white - this effectively hides the 0's but shows all positive (and negative!) values but the arithmetic still works
    Hope this more simple solution helps - I have found it a good idea to always have value fields in tables with a default value of 0 to avoid later math problems

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    You are correct. Adding a default value to existing data does not propagate throughout the existing data. In other words, it isn't retroactive.

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

Similar Threads

  1. Replies: 2
    Last Post: 04-17-2017, 01:40 PM
  2. Null and 0 values
    By MoeIndustries in forum Reports
    Replies: 2
    Last Post: 12-04-2015, 06:39 AM
  3. Replies: 7
    Last Post: 12-04-2013, 01:55 PM
  4. Finding the Max Date and Null Values if Null
    By SpdRacerX in forum Queries
    Replies: 1
    Last Post: 02-03-2012, 06:29 AM
  5. null values
    By ippy in forum Queries
    Replies: 3
    Last Post: 12-20-2010, 10:39 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