Results 1 to 2 of 2
  1. #1
    mkallover is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    25

    Query to count errors when records duplicate

    I'm trying to write a query to count unique errors on prescription claims submitted by pharmacies but I'm having an issue: A pharmacy can submit a claim multiple times and it can have multiple errors associated with it. What I would like to do is count only each unique occurrence of the error based on the Prescription ID.



    Code:
    CUST_ID PRESCRIPTION_ID ERR_CDE
    300 921928 256     
    300 921928 256     
    300 123456 123
    300 123456 256     
    300 123456 123
    300 123456 123
    320 954207 136     
    320 954207 136
    But in reality what I want to count is 1 occurrence of errors 123, 136 and 2 occurrences of 256. I already have a query that totals up all errors by CUST_ID but I'd like to modify it so that it will count only unique errors based on distinct PRESCRIPTION_ID.

    Here's the query I'm using:

    Code:
    TRANSFORM COUNT(ID) AS [COUNT]
    SELECT CUST_ID
    FROM tblClaims
    WHERE [ERR_CDE] IS NOT NULL
    GROUP BY CUST_ID
    PIVOT [ERR_CDE];
    ID is just the unique ID for each record.

    Any thoughts on this one?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Second time today I have offered this query structure as a suggestion:

    SELECT Err_Cde, Count(Err_Cde) AS CountOfErr_Cde
    FROM (SELECT Prescription_ID, Err_Cde
    FROM Table1
    GROUP BY Prescription_ID, Err_Cde) As Query1
    GROUP BY Err_Cde;
    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: 0
    Last Post: 07-13-2011, 08:32 AM
  2. ELSIF Query to Read Duplicate Records
    By Overzero in forum Queries
    Replies: 7
    Last Post: 06-03-2011, 01:38 PM
  3. How to not show duplicate records in query?
    By JimmD43 in forum Queries
    Replies: 3
    Last Post: 05-29-2011, 02:54 PM
  4. Query to count records
    By jpkeller55 in forum Access
    Replies: 4
    Last Post: 10-24-2010, 09:24 AM
  5. Replies: 1
    Last Post: 05-21-2010, 02:22 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