Count unique value with multiple criteria in a range

ExcelLearner_

New Member
Joined
May 23, 2018
Messages
7
Customer Name
Customer Add
ABC
Add 1
ABC
Add 2
CDE
Add 3
BFE ( CDE Finance)
Add 3

<tbody>
</tbody>

Hi guys,

I have a set of data consist of the below:
- Customer Name
- Customer Address
- Status
- Owner
- Type

I would like to count the number of customer with criteria
1. Status = Finalized
2. Owner = Bob
3. Type = Visit


The challenge as describe below (see table attached above)
1. one customer may have more than one address
2. one address may have more than one customer name.

Given all the criteria match, the total number of customer should be 2. (CDE & BFE are same entity with different subsidiary/department)

Tried using sum if together with 1/countifs formula - however it return 3...

Anyone can help shed some lights??

Many thanks in advance.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Given A1:B5, control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(IF(FREQUENCY(IF($B$2:$B$5<>"",MATCH($B$2:$B$5,$B$2:$B$5,0)),ROW($B$2:$B$5)-ROW($B$2)+1),$A$2:$A$5,"")<>"",MATCH(IF(FREQUENCY(IF($B$2:$B$5<>"",MATCH($B$2:$B$5,$B$2:$B$5,0)),ROW($B$2:$B$5)-ROW($B$2)+1),$A$2:$A$5,""),IF(FREQUENCY(IF($B$2:$B$5<>"",MATCH($B$2:$B$5,$B$2:$B$5,0)),ROW($B$2:$B$5)-ROW($B$2)+1),$A$2:$A$5,""),0)),ROW($A$2:$A$5)-ROW($A$2)+1),1))
 
Upvote 0
It works !!

But can you enlighten me by explaining the logic please...?
Trying to wrap my mind around but could not get the concept ...
 
Upvote 0
Hi,
I manage to figure out how the formula works .. but how do I incorporate the criteria into the formula?

screenshot.png
 
Last edited by a moderator:
Upvote 0
Customer NameCustomer AddOwnerStatusType
ABCAdd 1BobFinalizedVisit
CCDAdd 4SteveFinalizedVisit
EEFAdd 5BobOpenVisit
FGHAdd 6BobFinalizedCall
ABCAdd 2BobFinalizedVisit
CDEAdd 3BobFinalizedVisit
BFEAdd 3BobFinalizedVisit

Hi,
I manage to figure out how the formula works .. but how do I incorporate the criteria into the formula?


sorry the screen shot seems missing when I post...
Table as illustrated above ...
 
Last edited by a moderator:
Upvote 0
Customer Name
Customer Add
Owner
Status
Type
ABC
Add 1
Bob
Finalized
Visit
CCD
Add 4
Steve
Finalized
Visit
EEF
Add 5
Bob
Open
Visit
FGH
Add 6
Bob
Finalized
Call
ABC
Add 2
Bob
Finalized
Visit
CDE
Add 3
Bob
Finalized
Visit
BFE
Add 3
Bob
Finalized
Visit

<tbody>
</tbody>



sorry the screen shot seems missing when I post...
Table as illustrated above ...

What are the additional criteria? How many - 3 as in Owner = Bob, Status = Finalized, and Type = Visit?
 
Upvote 0
Ya, I want to count the number of customer only if
1. Owner = Bpb and
2. Status = Finalized and
3. Type = Visit
Book1
ABCDEFG
1Customer NameCustomer AddOwnerStatusTypebob
2ABCAdd 1BobFinalizedVisitfinalized
3CCDAdd 4SteveFinalizedVisitvisit
4EEFAdd 5BobOpenVisit2
5FGHAdd 6BobFinalizedCall
6ABCAdd 2BobFinalizedVisit
7CDEAdd 3BobFinalizedVisit
8BFEAdd 3BobFinalizedVisit
Sheet2

In G4 control+shift+enter, not just enter:
Excel Formula:
=SUM(IF(FREQUENCY(IF(IF(FREQUENCY(IF(($B$2:$B$8<>"")*($C$2:$C$8=G$1)*($D$2:$D$8=G$2)*($E$2:$E$8=G$3),MATCH($B$2:$B$8,$B$2:$B$8,0)),ROW($B$2:$B$8)-ROW($B$2)+1),$A$2:$A$8,"")<>"",MATCH(IF(FREQUENCY(IF(($B$2:$B$8<>"")*($C$2:$C$8=G$1)*($D$2:$D$8=G$2)*($E$2:$E$8=G$3),MATCH($B$2:$B$8,$B$2:$B$8,0)),ROW($B$2:$B$8)-ROW($B$2)+1),$A$2:$A$8,""),IF(FREQUENCY(IF(($B$2:$B$8<>"")*($C$2:$C$8=G$1)*($D$2:$D$8=G$2)*($E$2:$E$8=G$3),MATCH($B$2:$B$8,$B$2:$B$8,0)),ROW($B$2:$B$8)-ROW($B$2)+1),$A$2:$A$8,""),0)),ROW($A$2:$A$8)-ROW($A$2)+1),1))

What follows are more manageable versions...

Let's assign the ranges in the data area relevant names: cusname, cusadd, owner, status, and type. And let's also define ivec (from integer vector) via Formulas | Name Manager as referring to:
Excel Formula:
=ROW(cusname)-ROW(INDEX(Cusname,1,1))+1

Using these definitions the formula we have becomes more readable: Control+shift+enter…
Excel Formula:
=SUM(IF(FREQUENCY(IF(IF(FREQUENCY(IF((cusadd<>"")*(owner=G$1)*(status=G$2)*(type=G$3),MATCH(cusadd,cusadd,0)),ivec),cusname,"")<>"",MATCH(IF(FREQUENCY(IF((cusadd<>"")*(owner=G$1)*(status=G$2)*(type=G$3),MATCH(cusadd,cusadd,0)),ivec),cusname,""),IF(FREQUENCY(IF((cusadd<>"")*(owner=G$1)*(status=G$2)*(type=G$3),MATCH(cusadd,cusadd,0)),ivec),cusname,""),0)),ivec),1))

If so desired, we can make the formula a bit more efficient by using a non-native function written in VBA. The formula then becomes:
Excel Formula:
=SUM(IF(FREQUENCY(IF(V(IF(FREQUENCY(IF((cusadd<>"")*(owner=G$1)*(status=G$2)*(type=G$3),MATCH(cusadd,cusadd,0)),ivec),cusname,""))<>"",MATCH(V(),V(),0)),ivec),1))

For the foregoing formula to work, we need to install the V() function using Alt+F11 of which the code is as follows:
VBA Code:
Public Function V(Optional vrnt As Variant) As Variant
'
' Stephen Dunn
' 2002-09-12
'
Static vrntV As Variant
If Not IsMissing(vrnt) Then vrntV = vrnt
V = vrntV
End Function
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,655
Messages
6,120,760
Members
448,991
Latest member
Hanakoro

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