Results 1 to 3 of 3
  1. #1
    scampbell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    12

    Totals Query - Independent criteria


    Hello All,

    I figured out this problem a while back, but overwrote it (sigh) and for the life of me cannot figure it out again. I'm creating a query of totals from a certain table (MASTER). This query will eventually just have one row of totals. Now, this is going to sound like a waste of a query as I believe this part can all be done directly in a report (the final end of this process) but there has been a request to save these totals to a table every time the query is run for historical purposes.

    Anyway, the problem comes when I want to put a criteria on one of the counts without affecting the others. I believe I did this strictly by writing an expression before, but like I said can't recreate it. So let's say I have fields Index, PID, and SCOPE. For the first two, I just add them to the totals query and ask for a count, no big deal. For the third, SCOPE can either be "Yes" or "No" (or blank, in theory). I want the get a count of all of the items with "Yes" in the scope field, without it affecting the other two counts (I don't want separate counts of Index for "Yes", "No" and blank SCOPE).

    Code:
    SELECT Count(MASTER.Index) AS CountOfIndex, Count(MASTER.PID) AS CountOfPID, Count([MASTER].[SCOPE]<>"NO") AS Expr1FROM MASTER;
    This is what I have tried among a million other things. This is probably the closest I have come, but the count it gives is for "Yes" or "No", omitting only NULL results. How can I change this to get only the "Yes" items?

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is SCOPE a Yes/No type?

    Try:

    Sum([SCOPE])

    or

    Sum(Abs([SCOPE]))

    If it is text, try:

    Sum(IIf([SCOPE]="Yes",1,0))
    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
    scampbell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    12
    Perfect! Much appreciated.

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

Similar Threads

  1. Query - using Max Totals with Criteria
    By mslieder in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:02 AM
  2. Totals Query Record Count with Criteria
    By rmoreno in forum Queries
    Replies: 3
    Last Post: 06-07-2013, 09:16 AM
  3. Replies: 5
    Last Post: 12-06-2011, 11:18 AM
  4. Replies: 1
    Last Post: 06-12-2011, 07:08 AM
  5. Replies: 0
    Last Post: 04-23-2009, 09:42 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