Distinct Count a Column Based on Criteria from Other Columns

shellp

Board Regular
Joined
Jul 7, 2010
Messages
194
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
FyearMISRescodeTreating_HospitalHCNVisits
2018Dialysis_Home0240Grey-Sloane5555555555
1​
2018Dialysis_Home0240Grey-Sloane5555555555
1​
2018Dialysis_Other0200Grey-Sloane4444444444
1​
2018Dialysis_Other0232Sunshine Hospital5555555555
1​
2018Dialysis_Other0240Grey-Sloane5555555555
1​
2019Dialysis_Home0200Sunshine Hospital4444444444
1​
2019Dialysis_Home0232Grey-Sloane5555555555
1​
2019Dialysis_Home0240Grey-Sloane5555555555
1​
2019Dialysis_Other0200Grey-Sloane5555555555
1​
2019Dialysis_Other0240Sunshine Hospital5555555555
1​

For the table above, I'd like to find distinct count of the HCN field (unique identifier for patient) with the filters of fyear, MIS, rescode and treating hospital. So for the above, if the fiscal year is 2018, the MIS is dialysis_home, the rescode is 0240 and the treating hospital is Grey-Sloane, there should be 1 distinct patient.

I don't know how to link other posts but in an August 17, 2020 post about distinct counts based on patient IDs, Eric W responded with =SUM(SIGN(FREQUENCY(IF(C2:C6=G2,IF(D2:D6=H2,E2:E6)),E2:E6))) where E was the patient identifier. This works for my example if the HCN is a number field but in my case it is not so can Eric W's response be edited for use with text? Thanks for any and all assistance.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I am a bit confused with your Expected Answer. Do you want your expected answer to be this

Book1
ABCDEFG
1FyearMISRescodeTreating_HospitalHCNVisitsExpected Answer
22018Dialysis_Home240Grey-Sloane555555555511
32018Dialysis_Home240Grey-Sloane555555555512
42018Dialysis_Other200Grey-Sloane444444444411
52018Dialysis_Other232Sunshine Hospital555555555511
62018Dialysis_Other240Grey-Sloane555555555513
72019Dialysis_Home200Sunshine Hospital444444444411
82019Dialysis_Home232Grey-Sloane555555555511
92019Dialysis_Home240Grey-Sloane555555555514
102019Dialysis_Other200Grey-Sloane555555555511
112019Dialysis_Other240Sunshine Hospital555555555511
Sheet1
 
Upvote 0
is about:

  • SELECT DISTINCT returns only distinct (i.e. different) values.
  • SELECT DISTINCT eliminates duplicate records from the results.
  • DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc.
  • DISTINCT operates on a single column. DISTINCT for multiple columns is not supported.
so can you point here, if you don't mind
then maybe you got help
 
Upvote 0
Distinct here is the block on the wall.
so you are looking for
1​
different,
2​
disparate,
3​
dissimilar,
4​
distant,
5​
distinctive,
6​
distinguishable,
7​
diverse,
8​
nonidentical,
9​
other,
10​
unalike,
11​
unlike
 
Upvote 0
@shellp
What version of Excel are you using?
Please update you account details to show this, as it affects which functions you can use.
 
Upvote 0
CA_Punit - sorry, no, I want totals for the periods as stated. I have the number of visits in my table for other reasons but should have excluded it for this example.
Fluff - I am using Excel 2010, thanks.
Montecarlo1212 - I am looking for distinct HCN based on: fiscal year, MIS, and treating hospital. As with CA_Punit, I shouldn't have included the visits column, I am looking for a summary formula on another worksheet from the above which is "raw data"

thanks to you all.
 
Upvote 0
How about
+Fluff New.xlsm
ABCDEF
1FyearMISRescodeTreating_HospitalHCNVisits
22018Dialysis_Home240Grey-Sloane55555555552
32018Dialysis_Home240Grey-Sloane44444442
42018Dialysis_Other200Grey-Sloane44444444441
52018Dialysis_Other232Sunshine Hospital55555555551
62018Dialysis_Other240Grey-Sloane55555555551
72019Dialysis_Home200Sunshine Hospital44444444441
82019Dialysis_Home232Grey-Sloane55555555551
92019Dialysis_Home240Grey-Sloane55555555551
102019Dialysis_Other200Grey-Sloane55555555551
112019Dialysis_Other240Sunshine Hospital55555555551
Main
Cell Formulas
RangeFormula
F2:F11F2=SUM(--(FREQUENCY(IF($A$2:$A$11=A2,IF($B$2:$B$11=B2,IF($C$2:$C$11=C2,IF($D$2:$D$11=D2,MATCH($E$2:$E$11,$E$2:$E$11,0))))),ROW($E$2:$E$11)-ROW($E$2)+1)>0))
Press CTRL+SHIFT+ENTER to enter array formulas.


PS. Don't forget to update your account details to show your version of Excel & then scroll down & click save. ;)
 
Upvote 0
Try This

Book4
ABCDEFGHIJKLMNOP
1FyearMISRescodeTreating_HospitalHCNVisitsDisctinct COUNT
22018Dialysis_Home240Grey-Sloaneabc12018Dialysis_Home240Grey-Sloane1
32018Dialysis_Home240Grey-Sloaneabc1Enter with Control Shift & Enter
42018Dialysis_Home240Grey-Sloaneabc1
52018Dialysis_Other232Sunshine Hospitalabc1
62018Dialysis_Other240Grey-Sloaneabc1
72018Dialysis_Home240Grey-Sloaneabc1
82019Dialysis_Home232Grey-Sloaneabc1
92019Dialysis_Home240Grey-Sloaneabc1
102019Dialysis_Other200Grey-Sloaneabc1
112019Dialysis_Other240Sunshine Hospitalabc1
12
13
Sheet1
Cell Formulas
RangeFormula
N2N2=SUM(IFERROR(--(MATCH(MATCH(IF(($A$2:$A$11=J2)*($B$2:$B$11=K2)*(C2:C11=L2)*(D2:D11=M2),E2:E11),$E$2:$E$11,0),ROW($E$2:$E$11)-ROW(E2)+1,0)/(ROW($E$2:$E$11)-ROW(E2)+1)=1),0))
 
Upvote 0
There was a mistake in the formula

Try this
=SUM(IFERROR(FREQUENCY(IFERROR(MATCH(MATCH(IF(($A$2:$A$11=J2)*($B$2:$B$11=K2)*(C2:C11=L2)*(D2:D11=M2),E2:E11),$E$2:$E$11,0),ROW($E$2:$E$11)-ROW(E2)+1,0),FALSE),ROW($E$2:$E$11)-ROW(E2)+1)^0,0))
 
Upvote 0
Thanks for everyone's assistance. CA_Punit, unfortunately your formula doesn't seem to work. Fluff's works but I need to keep testing to see about speed - there are 44545 rows in the raw data sheet just doing one rescode took some time so adding others may impact it too much to use this method.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,826
Members
449,190
Latest member
rscraig11

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