Counting problem

sharshra

Active Member
Joined
Mar 20, 2013
Messages
404
Office Version
  1. 365
I have a table with one of the field having comma separated values. I want to count for each value in that field how many items are there. I´m sure there must be a simple way to do this.

For example, consider the table below. It has name of sales person & regions they cover. I would like to have a formula to list down how many sales persons are there for each region. Note that the actual table has thousands of values. I have taken just 4 rows for illustration.

Table -
Book1
CD
3NameRegion
4JamesParis, London, Madrid
5RogerLondon, Zurich
6ThomasZurich, Berlin, Paris, Warsaw
7AnthonyParis, Madrid
Sheet1


Output required -
Book1
EF
8RegionNo. of sales persons
9Paris3
10London2
11Madrid2
12Zurich2
13Berlin1
14Warsaw1
Sheet1
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
Excel Formula:
=COUNTIFS(D:D,"*"&E9&"*")
 
Upvote 0
how about
=COUNTIF($B$2:$B$5,"*"&A9&"*")
Book3
ABC
1NameRegion
2JamesParis, London, Madrid
3RogerLondon, Zurich
4ThomasZurich, Berlin, Paris, Warsaw
5AnthonyParis, Madrid
6
7
8RegionNo. of sales persons
9Paris33
10London22
11Madrid22
12Zurich22
13Berlin11
14Warsaw11
Sheet1
Cell Formulas
RangeFormula
C9:C14C9=COUNTIF($B$2:$B$5,"*"&A9&"*")
 
Upvote 0
Not on a PC at the mo. Try using =COUNTIF(range of cells,"*Paris*") as an example
 
Upvote 0
Thanks to etaf & Trever for quick response. Please note that the actual table has thousands of rows with each row containing tens of regions. The table in this thread is just an example with very limited values.

At present, I´m doing this in multiple steps. I would like to simplify this in a single step.
1. Breakdown the values in region to separate rows.
2. Remove duplicates & get unique values from the region field.
3. Count the sales persons in each region.
 
Upvote 0
I suspect a better way to do this , sure fluff will have a way

=UNIQUE(TRIM(TEXTSPLIT(TEXTJOIN(",",,B2:B5),,",")))
will give a unique range of regions
and then the count as fluff and i posted

probably be able to do both columns with 1 formula
Book3
ABCDEFG
1NameRegion
2JamesParis, London, Madrid
3RogerLondon, Zurich
4ThomasZurich, Berlin, Paris, Warsaw
5AnthonyParis, Madrid
6
7
8RegionNo. of sales persons
9Paris33
10London22
11Madrid22
12Zurich22
13Berlin11
14Warsaw11
Sheet1
Cell Formulas
RangeFormula
E9:E14E9=UNIQUE(TRIM(TEXTSPLIT(TEXTJOIN(",",,D2:D5),,",")))
G9:G14G9=COUNTIF($D$2:$D$5,"*"&E9&"*")
Dynamic array formulas.
 
Upvote 0
Oops! Sorry, Fluff. Forgot to include you:) Thanks to you as well (y)

As I mentioned in my last post, I´m already getting the required result using multiple steps. Countif formula comes in the last step.

The current method involves data manipulation before actually counting. I prefer to avoid these data manipulation steps & use pivot or formula or any better mechanism & get the same result, preferably in single step.
 
Upvote 0
maybe somethign like this
does it in 1 step
=LET(a,UNIQUE(TRIM(TEXTSPLIT(TEXTJOIN(",",,$D$2:$D$5),,","))),b,COUNTIF($D$2:$D$5,"*"&a&"*"),HSTACK(a,b))
i suspect may be a better to do this

Book3
ABCDEFG
1NameRegion
2JamesParis, London, Madrid
3RogerLondon, Zurich
4ThomasZurich, Berlin, Paris, Warsaw
5AnthonyParis, Madrid
6
7
8RegionNo. of sales persons
9Paris3
10London2
11Madrid2
12Zurich2
13Berlin1
14Warsaw1
Sheet1
Cell Formulas
RangeFormula
E9:F14E9=LET(a,UNIQUE(TRIM(TEXTSPLIT(TEXTJOIN(",",,D2:D5),,","))),b,COUNTIF($D$2:$D$5,"*"&a&"*"),HSTACK(a,b))
Dynamic array formulas.
 
Upvote 0
Another otion
Fluff.xlsm
CDEFG
1
2
3NameRegionRegionNo. of sales persons
4JamesParis, London, MadridParis3
5RogerLondon, ZurichLondon2
6ThomasZurich, Berlin, Paris, WarsawMadrid2
7AnthonyParis, MadridZurich2
8Berlin1
9Warsaw1
Data
Cell Formulas
RangeFormula
F4:G9F4=LET(a,DROP(REDUCE("",D4:D7,LAMBDA(x,y,UNIQUE(VSTACK(x,TRIM(TEXTSPLIT(y,,",")))))),1),HSTACK(a,COUNTIFS(D:D,"*"&a&"*")))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,959
Messages
6,175,649
Members
452,663
Latest member
MEMEH

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