Results 1 to 5 of 5
  1. #1
    Beerman is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2012
    Posts
    1

    Nz function not working

    I am trying to run a query based off of a single table that lists global shipments. Basicaly what I am trying to do is count the number of UPS shipments (Carrier) from each country, the problem is not all countries are sending via UPS and therefore it doesn't include that country on the results. Then once I run the month end Report, it excludes the country because it had a Null value in this query.

    SELECT[GPMO].[From Country], Count([GPMO].Carrier) AS CountofCarrier
    FROM[GPMO]
    WHERE(((GPMO].Carrier)="UPS"))
    GROUP BY[GPMO].[From Country]


    ORDER BY Count([GPMO].Carrier) DESC;

    I have tried:
    SELECT[GPMO].[From Country], Nz(Count([GPMO].Carrier),0)
    However this has not worked. Any suggestions?

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    One simple way is to create another aggregate query that just returns all your different countries.
    Then do a Left Join from this new query to the query you posted above, and it should show all the countries in it, and the total Carrier Count (will need to use the NZ function to return 0 in the place of Null for those without counts).

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    SELECT[GPMO].[From Country], Sum(iif([GPMO].Carrier = "UPS", 1, 0)) AS CountofCarrier
    FROM[GPMO]
    GROUP BY[GPMO].[From Country]
    ORDER BY Count([GPMO].Carrier) DESC;

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    rpeare,

    That's a clever way. I should have remembered that, I have used that method before in the past!

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    like a river I seek the path of least resistance

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

Similar Threads

  1. Sort function not working correctly
    By kristyspdx in forum Reports
    Replies: 2
    Last Post: 10-09-2012, 11:04 AM
  2. NZ() function not working?
    By EvanRosenlieb in forum Programming
    Replies: 6
    Last Post: 12-22-2011, 05:37 PM
  3. working as a vlookup function
    By cleon in forum Queries
    Replies: 3
    Last Post: 12-16-2011, 02:51 PM
  4. Outer Join query with function not working
    By davebrads in forum Queries
    Replies: 4
    Last Post: 11-02-2011, 03:05 AM
  5. Total Calculation, nz function, not working
    By Jojojo in forum Programming
    Replies: 3
    Last Post: 10-10-2011, 02:33 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