Finding Distinct Values with a Formula

oz74

New Member
Joined
Oct 24, 2022
Messages
11
Office Version
  1. 365
Platform
  1. MacOS
Hi

I need a formula which will count how many distinct values I have in a particular field in my dataset – I envisage something similar to COUNTIFS / SUMIFS. Below is a screenshot of my data:

1666886814701.png



The formula needs to count the number of distinct Customer IDs in a country but have the ability to add other conditions. For example, determining the number of distinct Customer IDs in Brazil who are Corporate Customers. I envisage this to be a stand-alone formula in a cell rather producing a list of countries. Below is a visualisation which may help:


1666886874580.png



I’ve also pasted the data as text to copy into Excel:

Country Customer ID Customer Type Sales ID
Argentina A515 Corporate B22598
Australia M877 Retail H98748
Bangladesh Y874 Retail K85974
Argentina A515 Corporate B58748
Belgium D874 Corporate Z87489
Australia S597 Retail H48712
Brazil T282 Corporate Q19123
Australia S597 Retail J98194
Austria F487 Corporate Q87458
Bahrain W874 Corporate U89859
Argentina A522 Retail C59845
Belgium D874 Corporate R88872
Belgium R784 Retail R11165
Brazil F456 Corporate D90822
Canada J765 Retail S90232
Chile A453 Retail A98123
Brazil F456 Corporate P00983
Brazil F456 Corporate S87321
Brazil K987 Corporate D90921
Chile P890 Retail A09123
Chile P890 Retail H34098


Thank you in advance for your help, much appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Can you do a straight copy/paste from excel to here (ie Ctrl C then Ctrl v) that way we get usable data like
PostCodeIn Use?LatitudeLongitudeEastingNorTHIGridRef
BN1 7GBYes
50.841392​
-0.130888​
531697​
106316​
TQ316063
CB25 0DUYes
52.277825​
0.326272​
558800​
266957​
TL588669
LS13 3DJYes
53.809715​
-1.639067​
423865​
434885​
TL588670
SO51 7SAYes
50.994629​
-1.49191​
435754​
121815​
SU357218
ST16 3QUYes
52.813977​
-2.093934​
393766​
324052​
SJ937240
E5 0QGYes
51.558042​
-0.054134​
534991​
186145​
TQ349861
SG13 7FZYes
51.800314​
-0.072611​
532999​
213053​
TL329130
SN2 1BDYes
51.569009​
-1.781816​
415219​
185593​
SU152855
TW3 1NNYes
51.470857​
-0.361684​
513889​
175927​
TQ138759

Rather than everything mixed in together like yours is
 
Upvote 0
Hi Fluff, Safari doesn't paste as a table of data but Chrome does so here it is:

CountryCustomer IDCustomer TypeSales ID
ArgentinaA515CorporateB22598
AustraliaM877RetailH98748
BangladeshY874RetailK85974
ArgentinaA515CorporateB58748
BelgiumD874CorporateZ87489
AustraliaS597RetailH48712
BrazilT282CorporateQ19123
AustraliaS597RetailJ98194
AustriaF487CorporateQ87458
BahrainW874CorporateU89859
ArgentinaA522RetailC59845
BelgiumD874CorporateR88872
BelgiumR784RetailR11165
BrazilF456CorporateD90822
CanadaJ765RetailS90232
ChileA453RetailA98123
BrazilF456CorporateP00983
BrazilF456CorporateS87321
BrazilK987CorporateD90921
ChileP890RetailA09123
ChileP890RetailH34098
 
Upvote 0
Thanks for that (y)
How about
Fluff.xlsm
ABCDEFG
1CountryCustomer IDCustomer TypeSales ID
2ArgentinaA515CorporateB22598Brazil2
3AustraliaM877RetailH98748Corporate
4BangladeshY874RetailK85974
5ArgentinaA515CorporateB58748Brazil3
6BelgiumD874CorporateZ87489
7AustraliaS597RetailH48712
8BrazilT282CorporateQ19123
9AustraliaS597RetailJ98194
10AustriaF487CorporateQ87458
11BahrainW874CorporateU89859
12ArgentinaA522RetailC59845
13BelgiumD874CorporateR88872
14BelgiumR784RetailR11165
15BrazilF456CorporateD90822
16CanadaJ765RetailS90232
17ChileA453RetailA98123
18BrazilF456CorporateP00983
19BrazilF456CorporateS87321
20BrazilK987RetailD90921
21ChileP890RetailA09123
22ChileP890RetailH34098
23
Details
Cell Formulas
RangeFormula
G2G2=ROWS(UNIQUE(FILTER(B2:B22,(A2:A22=F2)*(IF(F3="",1,C2:C22=F3)))))
G5G5=ROWS(UNIQUE(FILTER(B2:B22,(A2:A22=F5)*(IF(F6="",1,C2:C22=F6)))))
 
Upvote 0
Solution
Thanks for that (y)
How about
Thank you very much Fluff - it works brilliantly. To share - I've also added another condition to your formula:

Excel Formula:
=ROWS(UNIQUE(FILTER(B2:B22,(A2:A22=G5)*(IF(G6="",1,C2:C22=G6))*(IF(G7="",1,E2:E22=G7)))))

You've been incredibly helpful!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Similar threads

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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