Removing records based on Unique values and specific conditions

smeye011

New Member
Joined
Mar 23, 2016
Messages
16
Hello,

I’d like to find a solution to the following problem - preferably using pivot tables, but I can also use a work around with the raw data before running the pivot table if needed:

Essentially, my data lists medical encounters with criteria such as date of service, service code, client name, clinician name, and so on.

In any particular data set, there are likely to be numerous entries for the same client (with different dates, service codes, etc)

I’d like to find a way to remove data (or omit in the pivot field) based on these conditions:

If client A shows service code 90791, count the code towards total appointments for client A. If client A shows a code 90791, but also shows code 96101 in ANY other row of data, remove all records (or omit all data) for client A that will impact the pivot table.

I’m not sure if this is a filtering issue, or potentially could be used with the index/match function - any help would be greatly appreciated!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You can incorporate the requirements in the pivot table using

Code:
SELECT *
FROM YourTable
WHERE ClientName NOT IN 
(SELECT ClientName
FROM 
(SELECT DISTINCT ClientName, COUNT(ClientCode)
FROM YourTable
WHERE ClientName = 'A' AND ClientCode IN (90791,96101)
GROUP BY ClientName
HAVING COUNT(*) = 2))

Brief description of manual set up follows. With names to suit your field names, & source data's defined name. Save your data file with a simple defined name (I've assumed YourTable) for the source data. ALT-D-P to start the pivot table wizard, choose external data at the first step, follow the wizard to the end choosing the option at the last step to edit in MS Query. Edit the SQL as above (to suit your data & field names) and OK to acknowledge message about not being able to graphically represent. Exit MS Query & create & set up the pivot table.

HTH
 
Last edited:
Upvote 0
So I hadn't tested the solution earlier: when I did it was wrong.

After testing, please change earlier incorrect pivot table definition to
Code:
SELECT *
FROM YourTable
WHERE ClientName NOT IN
(SELECT ClientName
FROM (SELECT DISTINCT ClientName, ClientCode
FROM YourTable
WHERE ClientName = 'A' AND ClientCode IN (90791,96101))
GROUP BY ClientName
HAVING COUNT(*) = 2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top