Results 1 to 11 of 11
  1. #1
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154

    Problem with sum

    Dear all

    SELECT Registration.[ID], Registration.[Appl], Registration.[C_FULLNAME], Registration.[Lunch], Registration.[Culture], Registration.[Youth], Registration.[Opening], Registration.[Multimeida], Registration.[Wel_BNQ], Registration.[Lunch]+[Culture]+[Youth]+[Opening]+[Multimeida]+[Wel_BNQ] AS Total


    FROM Registration;


    I have problem in adding all these fields

    What's wrong?
    Eric
    Attached Thumbnails Attached Thumbnails Add_problem.JPG  

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try:
    Code:
    SELECT Registration.[ID], Registration.[Appl], Registration.[C_FULLNAME], Registration.[Lunch], Registration.[Culture], Registration.[Youth], Registration.[Opening], Registration.[Multimeida], Registration.[Wel_BNQ], Registration.Nz([Lunch],0)+Nz([Culture],0)+Nz([Youth],0)+Nz([Opening],0)+Nz([Multimeida],0)+Nz([Wel_BNQ],0) AS Total
    FROM Registration;
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    Bob

    Error
    Attached Thumbnails Attached Thumbnails Undefine.JPG  

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Maybe:
    Code:
    SELECT Registration.[ID], Registration.[Appl], Registration.[C_FULLNAME], Registration.[Lunch], Registration.[Culture], Registration.[Youth], Registration.[Opening], Registration.[Multimeida], Registration.[Wel_BNQ], Nz([Lunch],0)+Nz([Culture],0)+Nz([Youth],0)+Nz([Opening],0)+Nz([Multimeida],0)+Nz([Wel_BNQ],0) AS Total
    FROM Registration;
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    Bob

    How does it work . it is done

    Nz([Lunch],0)+Nz([Culture],0)+Nz([Youth],0)+Nz([Opening],0)+Nz([Multimeida],0)+Nz([Wel_BNQ],0) ?!

    NZ is a operator ? did i did anything wrong

    as the data are all imported so i have no control

    Eric

  6. #6
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    Bob

    Can you teach me one more formula to count if no blank

    See attached

    I can sum the Nites but for the room type, i only want to count those has records 雙床 (兩張單人床)"" / or better
    not blank .. as another hotelClick image for larger version. 

Name:	count_sum.JPG 
Views:	17 
Size:	87.0 KB 
ID:	29830 will have different names

    Thanks

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I believe the problem you had was that one of your fields contained Null values. AFAIK, a number + Null = Null
    Nz() is a function which looks for a null value in the value supplied as the first argument and returns the value of the second argument if the first is null.
    See: http://www.fmsinc.com/microsoftaccess/vba/nz.htm
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    Bob

    Thanks but sorry for my ignorance, i a fresh hand

    How can i handle it, perherps i go to Queries and base the report on Query ?

    AFAIK, a number + Null = Null, to me i do not understand

    Eric

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by Erictsang View Post
    Bob

    Can you teach me one more formula to count if no blank

    See attached

    I can sum the Nites but for the room type, i only want to count those has records 雙床 (兩張單人床)"" / or better
    not blank .. as another hotelClick image for larger version. 

Name:	count_sum.JPG 
Views:	17 
Size:	87.0 KB 
ID:	29830 will have different names

    Thanks
    Sorry, but I don't understand your requirement.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    Erictsang is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    154
    Bob

    In that case i want to count only if the field got the word 雙床 (兩張單人床)""
    The answer should be 5 instead of 9

    Eric

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Simple arithmetic with multiple fields when any field is null will return null as result regardless of value in other fields.

    The aggregate calculation to conditionally exclude records with null field:

    =Count(IIf(IsNull([Room_Type]), Null, 1))

    or

    =Count(IIf([Room_Type] Is Null, Null, 1))

    or

    =Sum(IIf(IsNull([Room_Type]), 0, 1))

    or

    =Sum(IIf([Room_Type] Is Null, 0, 1))
    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: 07-06-2015, 01:47 AM
  2. Replies: 2
    Last Post: 10-31-2012, 11:52 AM
  3. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  4. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 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