Count distinct values in column X based on unique value in col Y

creative999

Board Regular
Joined
Jul 7, 2021
Messages
114
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
I want to count distinct values based in col B but this needs to be based on unique values in col A.

Example below.

example.xlsx
ABC
1PRODPRODID
2RESALEABC
3RESALEABC
4RESALEABCABC = 1
5RESALEDEF
6RESALEDEF
7RESALEDEFDEF = 1
8RESALEIJKIJK = 1
9MANUIJK
10MANUDEFDEF - 1
11MANUIJK
12MANUIJK
13MANUIJKIJK = 1
14DELABC
15DELABC
16DELABC
17DELABC
18DELABCABC = 1
19DELDEF
20DELDEF
21DELDEF
22DELDEFDEF = 1
23DELIJKIJK = 1
24RESALE 2DEF
25RESALE 2DEF
26RESALE 2DEF
27RESALE 2DEF
28RESALE 2DEF
29RESALE 2DEFDEF = 1
30RESALE 2ABC
31RESALE 2ABC
32RESALE 2ABCABC = 1
33
34
35TOTALSABC = 3
36DEF = 4
37IJK.= 3
report1675758552260
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Here is one way:

Book1
ABCDE
1PRODPRODID
2RESALEABCABC3
3RESALEABCDEF4
4RESALEABCIJK3
5RESALEDEF
6RESALEDEF
7RESALEDEF
8RESALEIJK
9MANUIJK
10MANUDEF
11MANUIJK
12MANUIJK
13MANUIJK
14DELABC
15DELABC
16DELABC
17DELABC
18DELABC
19DELDEF
20DELDEF
21DELDEF
22DELDEF
23DELIJK
24RESALE 2DEF
25RESALE 2DEF
26RESALE 2DEF
27RESALE 2DEF
28RESALE 2DEF
29RESALE 2DEF
30RESALE 2ABC
31RESALE 2ABC
32RESALE 2ABC
Sheet4
Cell Formulas
RangeFormula
D2:E4D2=LET(x,UNIQUE(B2:B32),HSTACK(x,MAP(x,LAMBDA(y,IFERROR(ROWS(UNIQUE(FILTER(A2:A32,B2:B32=y))),0)))))
Dynamic array formulas.
 
Upvote 0
Works a treat.
How would i expand this if I wanted an extra condition, ie count only with a status of Closed:

example.xlsx
ABCD
1PRODPRODIDSTATUS
2RESALEABCOPEN
3RESALEABCOPEN
4RESALEABCOPENABC = 1
5RESALEDEFOPEN
6RESALEDEFOPEN
7RESALEDEFOPENDEF = 1
8RESALEIJKOPENIJK = 1
9MANUIJKCLOSED
10MANUDEFCLOSEDDEF - 1
11MANUIJKCLOSED
12MANUIJKCLOSED
13MANUIJKCLOSEDIJK = 1
14DELABCIN PROGRESS
15DELABCIN PROGRESS
16DELABCIN PROGRESS
17DELABCIN PROGRESS
18DELABCIN PROGRESSABC = 1
19DELDEFIN PROGRESS
20DELDEFIN PROGRESS
21DELDEFIN PROGRESS
22DELDEFIN PROGRESSDEF = 1
23DELIJKIN PROGRESSIJK = 1
24RESALE 2DEFOPEN
25RESALE 2DEFOPEN
26RESALE 2DEFOPEN
27RESALE 2DEFOPEN
28RESALE 2DEFOPEN
29RESALE 2DEFOPENDEF = 1
30RESALE 2ABCOPEN
31RESALE 2ABCOPEN
32RESALE 2ABCOPENABC = 1
report1675758552260
 
Upvote 0
Answer_Reddit.xlsx
ABCDE
1PRODPRODIDSTATUSABC0
2RESALEABCOPENDEF1
3RESALEABCOPENIJK1
4RESALEABCOPEN
5RESALEDEFOPEN
6RESALEDEFOPEN
7RESALEDEFOPEN
8RESALEIJKOPEN
9MANUIJKCLOSED
10MANUDEFCLOSED
11MANUIJKCLOSED
12MANUIJKCLOSED
13MANUIJKCLOSED
14DELABCIN PROGRESS
15DELABCIN PROGRESS
16DELABCIN PROGRESS
17DELABCIN PROGRESS
18DELABCIN PROGRESS
19DELDEFIN PROGRESS
20DELDEFIN PROGRESS
21DELDEFIN PROGRESS
22DELDEFIN PROGRESS
23DELIJKIN PROGRESS
24RESALE 2DEFOPEN
25RESALE 2DEFOPEN
26RESALE 2DEFOPEN
27RESALE 2DEFOPEN
28RESALE 2DEFOPEN
29RESALE 2DEFOPEN
30RESALE 2ABCOPEN
31RESALE 2ABCOPEN
32RESALE 2ABCOPEN
Sheet6
Cell Formulas
RangeFormula
D1:E3D1=LET(x,UNIQUE(B2:B32),HSTACK(x,MAP(x,LAMBDA(y,IFERROR(ROWS(UNIQUE(FILTER(A2:A32,(B2:B32=y)*(C2:C32="Closed")))),0)))))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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