Count Unique Values Based On Criteria

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
922
Office Version
  1. 365
Hi,

I have the following:

Book1
BCDEFGHIJK
2Sheet1Sheet 4
3Customer IDPolicy NoStateCityZip CodeStateCityZip CodeNo of Customer
4100077889745MontgomeryAlabama36104MontgomeryAlabama361046
5100177889746MontgomeryAlabama36104TexasDallas354783
6100277889747TexasDallas35478FloridaTallahassee878956
7100077889748MontgomeryAlabama36104MissouriJefferson City336586
8100477889749FloridaTallahassee87895
9100577889750FloridaTallahassee87895
10100677889751MissouriJefferson City33658
11100077889752MontgomeryAlabama36104
12100877889753MissouriJefferson City33658
13
14
15Sheet2
16Customer IDPolicy NoStateCityZip Code
17100088784487MontgomeryAlabama36104
18100188784488MontgomeryAlabama36104
19100288784489TexasDallas35478
20100088784490MontgomeryAlabama36104
21100488784491FloridaTallahassee87895
22100588784492FloridaTallahassee87895
23100688784493MissouriJefferson City33658
24100088784494MontgomeryAlabama36104
25100888784495MissouriJefferson City33658
26
27
28Sheet3
29Customer IDPolicy NoStateCityZip Code
30100099874587MontgomeryAlabama36104
31100199874588MontgomeryAlabama36104
32100299874589TexasDallas35478
33100099874590MontgomeryAlabama36104
34100499874591FloridaTallahassee87895
35100599874592FloridaTallahassee87895
36100699874593MissouriJefferson City33658
37100099874594MontgomeryAlabama36104
38100899874595MissouriJefferson City33658
Sheet1


In Sheet 1 to Sheet3, I have the customer ID,, their policy no, state ,city and zip code. In Sheet4, i am trying to count the unique number of customers based on customer ID in each state and city. Example, for Montgomery, Alabama, based on unique customer ID, there is a total of 6 customers. I am unable to combine the list in Sheet 1 to 3 due to each sheet has a long list of customer details.

Is there a way to build a formula to look into sheet 1 to 3 and populate the result in Sheet4? Example of the correct result is in Sheet4. Appreciate all the help. 🙏
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
How about
Excel Formula:
=LET(v,VSTACK(Sheet1:Sheet3!$A$2:$D$100),ROWS(UNIQUE(FILTER(TAKE(v,,1),(INDEX(v,,3)=G3)*(INDEX(v,,4)=H3)))))
 
Upvote 0
Hi Fluff,

Thank you for you solution. I dont have Vstack in the desktop version of my company but its available in the online version. But when I tried to open in Excel online, it says unable to open in Excel Online because it exceeds 100MB. Is there another alternative for the formula ?
 
Upvote 0
Ok, how about
Excel Formula:
=LET(a,Sheet1!$A$2:$D$100,b,Sheet2!$A$2:$D$100,c,Sheet3!$A$2:$D$100,ra,ROWS(a),rb,ra+ROWS(b),s,SEQUENCE(rb+ROWS(c)),x,IF(s<=ra,a,IF(s<=rb,INDEX(b,s-ra,{1,2,3,4}),INDEX(c,s-rb,{1,2,3,4}))),ROWS(UNIQUE(FILTER(INDEX(x,,1),(INDEX(x,,3)=G3)*(INDEX(x,,4)=H3)))))
 
Upvote 0
Hi Fluff,

Thank you for your response. Just to confirm, in the example of the table, this formula should be in cell H4?
 
Upvote 0
I've go it in J but you can put it where-ever you want
Fluff.xlsm
GHIJ
1Sheet 4
2StateCityZip CodeNo of Customer
3MontgomeryAlabama361042
4TexasDallas354781
5FloridaTallahassee878952
6MissouriJefferson City336582
Lists
Cell Formulas
RangeFormula
J3:J6J3=LET(a,Sheet1!$A$2:$D$100,b,Sheet2!$A$2:$D$100,c,Sheet3!$A$2:$D$100,ra,ROWS(a),rb,ra+ROWS(b),s,SEQUENCE(rb+ROWS(c)),x,IF(s<=ra,a,IF(s<=rb,INDEX(b,s-ra,{1,2,3,4}),INDEX(c,s-rb,{1,2,3,4}))),ROWS(UNIQUE(FILTER(INDEX(x,,1),(INDEX(x,,3)=G3)*(INDEX(x,,4)=H3)))))
 
Upvote 0
Solution
Hi Fluff,

Thank you for the solution. Appreciate your patience and have a great day ahead.🙏
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,236
Messages
6,123,798
Members
449,127
Latest member
Cyko

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