Count unique rows containing text without duplicating

Eskuppe

New Member
Joined
Sep 11, 2017
Messages
5
Hi,

I hope one of you Excel legends has a solution to my issue.

We have a report that has a column of data that looks like this:

Customers
BOB, DAV, HAR, JOH, PAU, PET, PHI, PRA, RYA
BOB, HAR, PAU, PHI, PRA
DAV, JOH, PET, PRA, RYA
DAV, HAR, JOH
BOB, DAV, PET

<tbody>
</tbody>

We count how many times each abbreviation comes up per row. I've been using =COUNTIF(range, "*BOB*") which would return 3.

What we need is to count how many times EITHER PAU, PET, PHI or PRA appear. So in the above example, we would need it to return a value of 4.

We're currently getting the total of all the times each one appears so PAU (2) + PET (3) + PHI (2) + PRA (3) = 8. The fact that I'm using * to search within the cell is making it hard to use SUBPRODUCT or DCOUNTA, or a ridiculous amount of COUNTIFS formulas.

Is there a way we can return the amount of unique rows containing either of the four abbreviations mentioned?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
what about a query? (or with same SQL to a pivot table)
untested

SELECT COUNT(*)
FROM YourTable
WHERE FieldName = '*PAU*' OR FieldName = '*PET*' OR FieldName = '*PHI*' OR FieldName = '*PRA*'

Brief description. So if your table has defined name YourTable and field name FieldName and the file is saved,
ALT-D-D-N & follow the wizard. At last step take option to edit in MS Query and change SQL to above. OK & see result
Open door icon to exit MS Query & make a query (or pivot) table in a worksheet

cheers
 
Upvote 0
Also, if this is what you need, control+shift+enter, not just enter:

Using MMULT...

=SUM(IF(MMULT(ISNUMBER(SEARCH(TRANSPOSE(","&$B$1:$B$4&","),","&SUBSTITUTE($A$2:$A$6," ","")&","))+0,ROW($B$1:$B$4)^0),1))

Without MMULT...

=SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH(","&TRANSPOSE($B$1:$B$4)&",",","&SUBSTITUTE($A$2:$A$6," ","")&",")),ROW($A$2:$A$6)),ROW($A$2:$A$6)),1))

A1:A6 houses the data and B1:B4 the customers of interest...

CustomersPAU
BOB, DAV, HAR, JOH, PAU, PET, PHI, PRA, RYAPET
BOB, HAR, PAU, PHI, PRAPHI
DAV, JOH, PET, PRA, RYAPRA
DAV, HAR, JOH
BOB, DAV, PET

<tbody>
</tbody>
 
Upvote 0
what about a query? (or with same SQL to a pivot table)
untested

SELECT COUNT(*)
FROM YourTable
WHERE FieldName = '*PAU*' OR FieldName = '*PET*' OR FieldName = '*PHI*' OR FieldName = '*PRA*'

Brief description. So if your table has defined name YourTable and field name FieldName and the file is saved,
ALT-D-D-N & follow the wizard. At last step take option to edit in MS Query and change SQL to above. OK & see result
Open door icon to exit MS Query & make a query (or pivot) table in a worksheet

cheers

Thanks for your suggestion and quick response. I'm not very familiar with SQL. I did try it per your instructions and I must be doing something wrong because it's not quite working for me.

Also, if this is what you need, control+shift+enter, not just enter:

Using MMULT...

=SUM(IF(MMULT(ISNUMBER(SEARCH(TRANSPOSE(","&$B$1:$B$4&","),","&SUBSTITUTE($A$2:$A$6," ","")&","))+0,ROW($B$1:$B$4)^0),1))

Without MMULT...

=SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH(","&TRANSPOSE($B$1:$B$4)&",",","&SUBSTITUTE($A$2:$A$6," ","")&",")),ROW($A$2:$A$6)),ROW($A$2:$A$6)),1))

A1:A6 houses the data and B1:B4 the customers of interest...

CustomersPAU
BOB, DAV, HAR, JOH, PAU, PET, PHI, PRA, RYAPET
BOB, HAR, PAU, PHI, PRAPHI
DAV, JOH, PET, PRA, RYAPRA
DAV, HAR, JOH
BOB, DAV, PET

<tbody>
</tbody>

This works like an absolute charm! Thank you so much! Are there any advantages to using MMULT or not using it? They are both yielding the same results.
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,930
Members
449,479
Latest member
nana abanyin

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