Counting Duplicate Values Only Once in a Column B by Matching Criteria in Column A

TheRussian68

New Member
Joined
May 26, 2016
Messages
15
Question should be straight forward. I searched and being a newbie didn't find a solution - at least one that I understood.

Assume the table below. I would like count the number of unique numbers from the each of the names (Cat, Dog, Mouse). The real world problem is I have about 800,000 call records where each row contains the name of the service customer subscribes to (represented by Cat, Dog, Mouse) and the actual subscription # associated with the outbound call. So I want to count the number of Unique Subscriptions that are found in the Subscription Column based on the unique Plan Name.

In the example below, I look at Column A, find each name (Say Cat) and then look at the corresponding value in Column B (Sub #) and count it exactly once. Cat has Sub # "1" found in row 2 and row 6 so I only count the occurrence of Sub # 1 exactly once. Cat has Sub # 2 occuring at row5 and Sub #3 at row 12. The value returned for unique subscriptions associated with all the Cat names is exactly 3 since we ignored the one occurrence of a duplicate (the Sub #1 ). Hopefully what I explained makes sense.

ABCDE
1NameSub #Name# Unique Sub
2Cat1Cat3
3Dog4Dog2
4Dog5Mouse3
5Cat2
6Cat1
7Mouse6
8Dog4
9Mouse7
10Dog5
11Mouse8
12Cat3

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

TheRussian68

New Member
Joined
May 26, 2016
Messages
15
I can do it by adding a helper column where I count the number of occurrences of a particular value in the row in the array from the top to where that value is found in the column - e.g. =COUNTIF($E$2:E21,E21). Then I can do a COUNTIFS on two criteria but was looking for a more elegant solution.
 

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
16,528
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Try

Array formula in E2 copied down
=SUM(IF(FREQUENCY(IF(A$2:A$12=D2,MATCH(B$2:B$12,B$2:B$12,0)),ROW(B$2:B$12)-ROW(B$2)+1),1))
Ctrl+Shift+Enter

If the column Sub# contains only numbers, not text, you can replace MATCH(B$2:B$12,B$2:B$12,0) by B$2:B$12

M.
 

D_Nelson

New Member
Joined
Nov 30, 2020
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Try

Array formula in E2 copied down
=SUM(IF(FREQUENCY(IF(A$2:A$12=D2,MATCH(B$2:B$12,B$2:B$12,0)),ROW(B$2:B$12)-ROW(B$2)+1),1))
Ctrl+Shift+Enter

If the column Sub# contains only numbers, not text, you can replace MATCH(B$2:B$12,B$2:B$12,0) by B$2:B$12

M.
This is perfect for what I am after. Just one question. What if column B was for dates. Is there a way of keeping it so that this formula where it matches A and counts single unique values after a particular date?
 

Watch MrExcel Video

Forum statistics

Threads
1,130,295
Messages
5,641,395
Members
417,207
Latest member
Vxhaet

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
Top