Count without duplicates

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I've a situation like the following:

column f column g
A ONE
A ONE
A TWO
A THREE
A THREE
B ONE
B ONE
B ONE
B TWO
A FOUR
A FOUR
A FOUR
A FOUR
A FIVE

I need a formula that counts how many differents values in column g for the value A in column f (in the example 5) and how many different values in column g for the value B in column f (in the example 2).

Thank you.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try


[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
F
[/td][td="bgcolor: #DCE6F1"]
G
[/td][td="bgcolor: #DCE6F1"]
H
[/td][td="bgcolor: #DCE6F1"]
I
[/td][td="bgcolor: #DCE6F1"]
J
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td][/td][td][/td][td][/td][td][/td][td]
CountUnique​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td]
A​
[/td][td]
ONE​
[/td][td][/td][td]
A​
[/td][td]
5​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td]
A​
[/td][td]
ONE​
[/td][td][/td][td]
B​
[/td][td]
2​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td]
A​
[/td][td]
TWO​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
5
[/td][td]
A​
[/td][td]
THREE​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
6
[/td][td]
A​
[/td][td]
THREE​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
7
[/td][td]
B​
[/td][td]
ONE​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
8
[/td][td]
B​
[/td][td]
ONE​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
9
[/td][td]
B​
[/td][td]
ONE​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
10
[/td][td]
B​
[/td][td]
TWO​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
11
[/td][td]
A​
[/td][td]
FOUR​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
12
[/td][td]
A​
[/td][td]
FOUR​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
13
[/td][td]
A​
[/td][td]
FOUR​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
14
[/td][td]
A​
[/td][td]
FOUR​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
15
[/td][td]
A​
[/td][td]
FIVE​
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Array formula in J2 copied down
=SUM(IF(FREQUENCY(IF(F$2:F$15=I2,MATCH(G$2:G$15,G$2:G$15,0)),ROW(G$2:G$15)-ROW(G$2)+1),1))
confirmed with Ctrl+Shift+Enter, not just Enter

M.
 
Upvote 0
Many thanks for the support: it works perfectly well.

Just add a constraint, if possible: to exclude the rows with value 0 in column h

column f column g column h
A ONE 7
A ONE 5
A TWO 0
A THREE 4
A THREE 2
B ONE 3
B ONE 0
B ONE 5
B TWO 6
A FOUR 0
A FOUR 2
A FOUR 4
A FOUR 3
A FIVE 2
 
Upvote 0
Maybe...


[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
F
[/td][td="bgcolor: #DCE6F1"]
G
[/td][td="bgcolor: #DCE6F1"]
H
[/td][td="bgcolor: #DCE6F1"]
I
[/td][td="bgcolor: #DCE6F1"]
J
[/td][td="bgcolor: #DCE6F1"]
K
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
CountUnique​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td]
A​
[/td][td]
ONE​
[/td][td]
7​
[/td][td][/td][td]
A​
[/td][td]
4​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td]
A​
[/td][td]
ONE​
[/td][td]
5​
[/td][td][/td][td]
B​
[/td][td]
2​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td]
A​
[/td][td]
TWO​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
5
[/td][td]
A​
[/td][td]
THREE​
[/td][td]
4​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
6
[/td][td]
A​
[/td][td]
THREE​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
7
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
3​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
8
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
9
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
5​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
10
[/td][td]
B​
[/td][td]
TWO​
[/td][td]
6​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
11
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
12
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
13
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
4​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
14
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
3​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
15
[/td][td]
A​
[/td][td]
FIVE​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Array formula in K2
=SUM(IF(FREQUENCY(IF(F$2:F$15=J2,IF(H$2:H$15<>0,MATCH(G$2:G$15,G$2:G$15,0))),ROW(G$2:G$15)-ROW(G$2)+1),1))
Ctrl+Shift+Enter

M.
 
Upvote 0
Maybe...


[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
F
[/td][td="bgcolor: #DCE6F1"]
G
[/td][td="bgcolor: #DCE6F1"]
H
[/td][td="bgcolor: #DCE6F1"]
I
[/td][td="bgcolor: #DCE6F1"]
J
[/td][td="bgcolor: #DCE6F1"]
K
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
CountUnique​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td]
A​
[/td][td]
ONE​
[/td][td]
7​
[/td][td][/td][td]
A​
[/td][td]
4​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td]
A​
[/td][td]
ONE​
[/td][td]
5​
[/td][td][/td][td]
B​
[/td][td]
2​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td]
A​
[/td][td]
TWO​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
5
[/td][td]
A​
[/td][td]
THREE​
[/td][td]
4​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
6
[/td][td]
A​
[/td][td]
THREE​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
7
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
3​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
8
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
9
[/td][td]
B​
[/td][td]
ONE​
[/td][td]
5​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
10
[/td][td]
B​
[/td][td]
TWO​
[/td][td]
6​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
11
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
12
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
13
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
4​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
14
[/td][td]
A​
[/td][td]
FOUR​
[/td][td]
3​
[/td][td][/td][td][/td][td][/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
15
[/td][td]
A​
[/td][td]
FIVE​
[/td][td]
2​
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Array formula in K2
=SUM(IF(FREQUENCY(IF(F$2:F$15=J2,IF(H$2:H$15<>0,MATCH(G$2:G$15,G$2:G$15,0))),ROW(G$2:G$15)-ROW(G$2)+1),1))
Ctrl+Shift+Enter

M.

Thank's: until today, it seems ok.

Now, I'm going to study the structure of the formula.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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