Count unique values across two columns

Wishmaster89

Board Regular
Joined
Jan 10, 2022
Messages
77
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Hi All

I am trying to count the number of ID's that start in 2017. I know you can do sumproduct with count if , but i couldnt't get it working with countifs.

Sample data below.

QAR withdrawal comparison.xlsx
AB
1IDStart_Year
212017
322017
432017
542017
652018
762017
872017
912018
1092017
11102017
1252018
13112017
14122017
15132017
1692018
Sheet1
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
=SUMPRODUCT(IF($B$2:$B$16=2017,1/COUNTIFS($B$2:$B$16,2017,$A$2:$A$16,$A$2:$A$16),""))
For Ex2016 or earlier, array formula requires Ctrl-Shift-Enter combination, instead of Enter
 
Upvote 0
Assuming that your ID's are numerical like your samples and that you are happy to be using your 2021 version

Excel Formula:
=COUNT(UNIQUE(FILTER(A2:A16,B2:B16=2017)))
 
Upvote 0
Thank you so much, they both worked. I do have a follow up question please.

On the sample data A-C is one tab and G-I is another but to make this example easier i've put them on one sheet.

I need to count anyone from A-C and G-I that have a start year of 2017 but I don't want to double count people. E.g, ID 1 is in both data sets but ID 33 is only in the second data set so he would be counted.

Book2
ABCDEFGHI
1IDStart_YearStatusIDStart_YearStatus
2120171120171
3220171220171
4320173320173
5420171420171
6520181520181
7620171620171
8720171720171
927201812720181
10920171920171
1110201711020171
12520186520181
1311201711120171
1412201711220171
1513201711320171
16920186920181
17120176120171
18320173320171
199002017690020171
203320171
Sheet1
 
Upvote 0
Do you happen to have the VSTACK function in your 2021 version?
A couple of options depending on the answer.
I have done it on two sheets

22 08 11.xlsm
ABC
1IDStart_YearStatus
2120171
3220171
4320173
5420171
6520181
7620171
8720171
92720181
10920171
111020171
12520186
131120171
141220171
151320171
16920186
17120176
18320173
1990020176
Sht1


22 08 11.xlsm
ABCDEF
1IDStart_YearStatusVSTACKNO VSTACK
21201711313
3220171
4320173
5420171
6520181
7620171
8720171
92720181
10920171
111020171
12520181
131120171
141220171
151320171
16920181
17120171
18320171
1990020171
203320171
Sht2
Cell Formulas
RangeFormula
E2E2=LET(vs,VSTACK('Sht1'!A2:B19,A2:B20),COUNT(UNIQUE(FILTER(INDEX(vs,0,1),INDEX(vs,0,2)=2017))))
F2F2=COUNT(UNIQUE(FILTERXML("<p><c>"&TEXTJOIN("</c><c>",1,IF('Sht1'!B2:B19=2017,'Sht1'!A2:A19,""),IF(B2:B20=2017,A2:A20,""))&"</c></p>","//c")))
 
Upvote 0
I had to re-edit my last post as there was some actual learner ID's that i didn't feel comfortable sharing.

Annoyingly my answer to Peter_SSs also dissapeared. I do have excel 365 but when typing in =VSTACK nothing appeared, not sure why. Anyway, i have put all of the tabs into one sheet to make it a bit easier. What i need to do now is count unique ID's that have Completion Status(B)=3 and Start Year(D)=2017. I have tried the formula in H2 but the result shows as 0.

QAR withdrawal comparison.xlsx
ABCDEFGH
1IDCompletion StatusStart DateStart YearLearning_Actual_End_Date convertedWithdrawal time frame(days - if applcable)MonthsStatus= 3 in 7-12 months
21626/07/2017201619/04/20182677-120
32317/01/2018201704/07/20181680-6
43605/07/2017201608/11/20171260-6
54328/11/2017201715/01/2018480-6
65311/07/2017201604/09/2017550-6
76324/07/2017201618/04/20182687-12
87327/07/2017201631/10/2017960-6
98627/07/2017201622/07/20183607-12
109611/07/2017201612/02/20182167-12
1110314/06/2017201616/08/2017630-6
1211623/02/2018201724/07/20181510-6
1312308/02/2018201713/06/20181250-6
1413620/09/20172017
1514607/07/2017201621/02/20182297-12
1615606/07/2017201618/06/20183477-12
1716607/07/2017201621/11/20171370-6
1817602/06/2017201618/06/2018381not in a category
1918319/06/2017201617/04/20183027-12
2019318/05/2017201616/03/20183027-12
2120327/07/2017201606/09/2017410-6
2221309/06/2017201623/08/2017750-6
2322323/06/2017201602/07/2018374not in a category
2423323/06/2017201616/05/20183277-12
2524305/07/2017201608/11/20171260-6
2625311/07/2017201612/03/20182447-12
2726327/06/2017201616/11/20171420-6
2827116/11/20162016
294328/11/2017201715/01/2018480-6
305311/07/2017201604/09/2017550-6
316324/07/2017201618/04/20182687-12
Sheet2
Cell Formulas
RangeFormula
H2H2=COUNT(UNIQUE(FILTER('Raw data'!$A$2:$A$31,($D$2:$D$5105=2017)*('Raw data'!$G$2:$G$5105=7-12))))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A29:A31Cell ValueduplicatestextNO
A2:A27Cell ValueduplicatestextNO
 
Upvote 0
when typing in =VSTACK nothing appeared, not sure why
Because it is only gradually being rolled out to some users until M/Soft is sure that is is robust enough to distribute to everybody.


I have tried the formula in H2 but the result shows as 0
Can't help with that as it refers to sheet 'Raw data' that we cannot see.

For the sample data that you have shown, try

Excel Formula:
=COUNT(UNIQUE(FILTER(A2:A31,(B2:B31=3)*(D2:D31=2017))))
 
Upvote 0
Solution
Because it is only gradually being rolled out to some users until M/Soft is sure that is is robust enough to distribute to everybody.



Can't help with that as it refers to sheet 'Raw data' that we cannot see.

For the sample data that you have shown, try

Excel Formula:
=COUNT(UNIQUE(FILTER(A2:A31,(B2:B31=3)*(D2:D31=2017))))
Thank you so much! Ah i thought i had changed the formula for the sample sheet not to include the raw data sheet reference. I must be going mad, before i asked on the forum i was googling and thinking of all sorts of ways to try and tackle this.

Thanks again.
 
Upvote 0
Is there a limit to how many columns i can add in to the * part of the formula below?

=COUNT(UNIQUE(FILTER(A2:A31,(B2:B31=3)*(D2:D31=2017))))
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
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