Results 1 to 5 of 5
  1. #1
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199

    Issue summing query fields when no data exists

    Hello,

    How can I sum multiple fields in a query. What's happening is that if there's 0's in those fields it simple excludes that whole row from my count (even if there's data in other fields of the calculation).

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Don't understand. 0 value should not exclude records.

    Post sql statement for analysis.
    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
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    Hello June7, it looks like those fields are actualyl Null, there are no 0s. however I used Nz in the calculation hoping to effect that. However what's happening it's simple summing only rows where all of these fields are already populated with data.


    SELECT [Mobile Data Input].Application, CLng(Nz([Mobile Data Input]![2010]+[Mobile Data Input]![2011]+[Mobile Data Input]![2012]+[Mobile Data Input]![2013]+[Mobile Data Input]![2014],0)) AS [Lifetime Downloads]FROM [Mobile Data Input]
    WHERE ((([Mobile Data Input].Application) Not In ("Application","Total")));

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Having a field for each year indicates a non-normalized data structure. Is that the structure of the raw data? A design that requires routine modification is problematic at best.

    Why using the CLng function?

    Arithmetic with null results in null. If you want to still sum the non-null fields need to use Nz() on each field.

    Nz([2010])+Nz([2011])+Nz([2012])+Nz([2013])+Nz([2014])
    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.

  5. #5
    accessmatt is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    199
    June7, BINGO, you nailed it again. The data I'm dealing with is terrible and I'm really using Access to normalize it through queries, etc.

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

Similar Threads

  1. Replies: 1
    Last Post: 07-17-2014, 05:51 PM
  2. Replies: 1
    Last Post: 02-27-2014, 07:59 PM
  3. Replies: 3
    Last Post: 11-26-2013, 03:40 PM
  4. Issue summing two field values
    By w2vijay in forum Reports
    Replies: 4
    Last Post: 02-10-2010, 01:53 AM
  5. Replies: 0
    Last Post: 01-24-2009, 11:40 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