Counting unique values in one column based on criteria in another column with result in a single cell

Monomeeth

New Member
Joined
Jun 3, 2015
Messages
2
Ok, have been struggling with this for a few hours, so am hoping someone can help me. I've designed an Excel Dashboard that displays a number of charts and tables based on a user selecting a month from a dropdown. Everything works fine, but today I wanted to add another category onto the Dashboard to provide some miscellaneous data.

For example, the first item at N36 is for "Total visitors up to selected month" and the second item at N37 is for "Unique visitors up to selected month", and so on.

I've got a formula in cell N36 that does the job for item 1 (although it's a very long formula with almost 2800 characters). Might be worth a separate post to see if there's a more elegant way to achieve the same result - but I digress!

Anyway, in cell N37 I want to add a formula that effectively counts UNIQUE values on another worksheet (let's just call it "DATA"). So, in the DATA sheet I want to count the number of unique values in column C based on criteria applied to column F.

All data in column F is entered as either "August 2014", "September 2014" and so on until "May 2015". The DATA sheet has over 20,000 rows of data. Below is a dummy example of sheet DATA:

First Name
Surname
User ID
Line
Group
Month
Fred
Flintstone
abcde
CAR
TRAN
September 2014
Homer
Simpson
acfge
BOO
LITE
January 2015
James
Bond
ab007
BOA
TRAN
May 2015
George
Jetson
acqwe
CAR
TRAN
August 2014
Fred
Flintstone
abcde
CAR
TRAN
October 2014
James
Bond
ab007
BOA
TRAN
February 2015
Homer
Simpson
acfge
BOO
LITE
November 2014
Homer
Simpson
acfge
BOO
LITE
December 2014
George
Jetson
acqwe
CAR
TRAN
March 2015
George
Jetson
acqwe
CAR
TRAN
April 2015
Fred
Flintstone
abcde
CAR
TRAN
January 2015

<TBODY>
</TBODY>

So, what I need in cell N37 of my Dashboard Sheet is a formula that will count the unique number of values in column C (i.e. the User ID column) based on criteria in column F that is determined by the user's selection in a dropdown (which places a value in cell L1)

For example, if the user has selected "August 2014" from the dropdown, then cell L1 displays "August 2014". So the formula in cell N37 is such that it will count all the unique values in column C of the "DATA" sheet that contain "August 2014" in the row at column F. However, the trick is that the criteria is cumulative. By that I mean that if the user selects "September 2014" then the formula needs to count all the unique values in column C of the "DATA" sheet that contain either "August 2014" or "September 2014" in the row at column F. Likewise, if they select "October 2014" then the formula needs to count all the unique values in column C of the "DATA" sheet that contain either "August 2014" or "September 2014" or "October 2014" in the row at column F.

This is because this cell is measuring "Unique visitors up to selected month". In this way it is designed to measure the number of unique visitors over the entire period. So, if a user visits the site every day from August 2014 until May 2015, they only get counted once. However, if the same user only visited the site once and that was in November 2014, then they aren't counted at all unless the Dashboard user has selected November 2014 or a later month.

I hope this all makes sense. LOL

Anyway, let's see how we go.

Thanks everyone!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
First NameSurnameUser IDLineGroupMonthcode1includedunique in included dates ?
FredFlintstoneabcdeCARTRANSep-149yesno
HomerSimpsonacfgeBOOLITEJan-1513yesno
JamesBondab007BOATRANMay-1517no
GeorgeJetsonacqweCARTRANAug-148yesno
FredFlintstoneabcdeCARTRANOct-1410yesno
JamesBondab007BOATRANFeb-1514yesno
HomerSimpsonacfgeBOOLITENov-1411yesno
HomerSimpsonacfgeBOOLITEDec-1412yesno
GeorgeJetsonacqweCARTRANMar-1515no
GeorgeJetsonacqweCARTRANApr-1516no
FredFlintstoneabcdeCARTRANJan-1513yesno
FredFlintstoneabcdeCARTRANSep-149yesno
HomerSimpsonacfgeBOOLITEJan-1513yesno
JamesBondab007BOATRANMay-1517nocode1
GeorgeJetsonacqweCARTRANAug-148yesnoAug-1489
FredUniquezzzzzCARTRANOct-1410yesyesSep-14910
JamesBondab007BOATRANFeb-1514yesnoOct-141011
HomerSimpsonacfgeBOOLITENov-1411yesnoNov-141112
HomerSimpsonacfgeBOOLITEDec-1412yesnoDec-141213
GeorgeJetsonacqweCARTRANMar-1515noJan-151314
GeorgeJetsonacqweCARTRANApr-1516noFeb-151415
FredFlintstoneabcdeCARTRANJan-1513yesnoMar-151516
Apr-151617
May-151718
select a monthFeb-1515
column I looks for unique id's only in the defined date range
formula in I2
=IF(H2="yes",IF(COUNTIF($C$2:$C$23,C2)=1,"yes","no"),"")

<colgroup><col width="64" span="15" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Hi oldbrewer, thanks for your response. I really appreciate it!

I think I must be missing something, or haven't explained my initial query very well.

Looking at your response I see you've added columns and you've given me the formula you're using in Column I, but I don't see how that helps me (hence why I'm not sure I've explained myself very well). So I'll clarify below.

In a nutshell, the user only sees one sheet "Dashboard" and I need a formula for cell N37 of that sheet. The formula will count all the unique visitors for a period of time. The period of time is based on the user selecting a month from a drop down menu (also on the Dashboard sheet) and this selection populates cell L1 (also on the Dashboard sheet). That is, if the user selects "December 2014" in the dropdown, then "December 2014" appears in cell L1.

So, what I need is a formula that counts the unique visitors listed at column C of another sheet (let's call this sheet "Data"). But the tricky bit is that I need it to count these unique visitors based on the period of time selected by the user. To help facilitate this, I've set up column F in the Data sheet to display the month. Below are two examples to further clarify.

Example 1: Simple

The user selects "August 2014". This is the first (and oldest) month on the list. The formula I need would then count all the unique visitors (listed at column C of the Data sheet) that have "August 2014" listed at column F of the Data sheet. In my actual workbook, this would return a value of 634 (i.e. I have 634 unique visitors for August 2014).


Example 2: Complicated

The user selects "February 2015". This is the seventh month on the list. The formula I need would then count all the unique visitors (listed at column C of the Data sheet) that have either "August 2014", "September 2014", "October 2014", "November 2014", "December 2014", "January 2014" or "February 2014" listed at column F of the Data sheet. In my actual workbook there are 14,209 rows in the Data sheet that contain one of the seven months listed. However, for that entire period (i.e. during the seven month period from Aug '14 til Feb '15) there were 6,389 unique visitors. That's because anyone who visited the site during that entire period is only counted once, regardless of whether they visited the site once or 10,000 times, regardless of whether they visited the site only in August 2014 or visited the site in each of the seven months. So, the formula I need would need to calculate a result of 6,389 if the user selected "February 2015", because that's the number of unique users for the entire period.


Additional comments
The Data sheet This sheet currently has over 20,000 rows of data and already lists only unique visitors by month. That is, using May 2015 as an example, during this month we had 37,838 views from 5,825 visitors. However, the number of unique visitors for the month was only 2,282. Therefore, the "Data" sheet only contains 2,282 rows of data for May 2015. I'm guessing I didn't make this clear earlier.

Another formula As I mentioned in my opening post, cell N36 displays Total visitors up to selected month. If it helps, the formula I have used in cell N36 of the Dashboard sheet is as follows:

=IF(L1="August 2014",COUNTIF(UniqueVisitors[Month],"August 2014"),IF(L1="September 2014",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014"),IF(L1="October 2014",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014"),IF(L1="November 2014",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014"),IF(L1="December 2014",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014"),IF(L1="January 2015",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014")+COUNTIF(UniqueVisitors[Month],"January 2015"),IF(L1="February 2015",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014")+COUNTIF(UniqueVisitors[Month],"January 2015")+COUNTIF(UniqueVisitors[Month],"February 2015"),IF(L1="March 2015",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014")+COUNTIF(UniqueVisitors[Month],"January 2015")+COUNTIF(UniqueVisitors[Month],"February 2015")+COUNTIF(UniqueVisitors[Month],"March 2015"),IF(L1="April 2015",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014")+COUNTIF(UniqueVisitors[Month],"January 2015")+COUNTIF(UniqueVisitors[Month],"February 2015")+COUNTIF(UniqueVisitors[Month],"March 2015")+COUNTIF(UniqueVisitors[Month],"April 2015"),IF(L1="May 2015",COUNTIF(UniqueVisitors[Month],"August 2014")+COUNTIF(UniqueVisitors[Month],"September 2014")+COUNTIF(UniqueVisitors[Month],"October 2014")+COUNTIF(UniqueVisitors[Month],"November 2014")+COUNTIF(UniqueVisitors[Month],"December 2014")+COUNTIF(UniqueVisitors[Month],"January 2015")+COUNTIF(UniqueVisitors[Month],"February 2015")+COUNTIF(UniqueVisitors[Month],"March 2015")+COUNTIF(UniqueVisitors[Month],"April 2015")+COUNTIF(UniqueVisitors[Month],"May 2015"),"?"))))))))))


Obviously the above formula is referencing named ranges, but you get the idea.

Hopefully this all helps to clarify things rather than confuse matters more!
 
Upvote 0
my "solution" allowed the user to select a month and then for that month and all previous months it searched for people that had only visited once, that was the misunderstanding. I will give it some more thought..........
 
Upvote 0
iddate visitedis date in range
129901/01/2015yes
123505/01/2015yes
123609/01/2015yes01/02/2015
123713/01/2015yes01/03/2015
123817/01/2015yes01/04/2015
123921/01/2015yes01/05/2015
124025/01/2015yes01/06/2015
124129/01/2015yes01/07/2015
124202/02/2015yes
124306/02/2015yes
124410/02/2015yes
123414/02/2015yes
123518/02/2015yes
123622/02/2015yesunique visitors before this date01/05/2015
123726/02/2015yes
123802/03/2015yescould easily be selected by a drop down
123906/03/2015yes
124010/03/2015yes
124114/03/2015yes
124218/03/2015yes
124322/03/2015yesis date in rangeyes
124426/03/2015yes
124530/03/2015yesCount of id
124603/04/2015yesidTotal
123907/04/2015yes12341
124011/04/2015yes12352
124115/04/2015yes12362
124219/04/2015yes12372
124323/04/2015yes12382
124427/04/2015yes12393
123401/05/2015no12403
123505/05/2015no12413
123609/05/2015no12423
123713/05/2015no12433
123817/05/2015no12443
123921/05/2015no12451
124025/05/2015no12461
123429/05/2015no12991
123502/06/2015noGrand Total30
123606/06/2015no
the pivot table lists each id for the selected timescale
as you say the total number of visits is irrelevant

<colgroup><col><col><col><col span="4"><col><col><col span="2"><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,216,127
Messages
6,129,022
Members
449,481
Latest member
joaotcosta23

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