counting unique instances in data set meeting multiple criteria

rjheibel

New Member
Joined
Mar 8, 2018
Messages
42
I need a formula that will be able to count the number of days that a persons name appears in a large data set within a defined date range. The issue I am having is that the persons name will likely have multiple entries on the same day, and i only want to count the first instance. Any help is greatly appreciated.

An example data set is below. I want to determine formula in G7:G10 to count how many days the people listed in F7:F10 have an entry in the dataset A4:C25, within the date range in G1:G2.


ABCDEFG
1Start date11/1/2018
2End Date2/17/2018
3Date PersonCode
415-FebBob100
515-FebBob110
615-FebBob300Days with an entry
715-FebFrank500Bob3
815-FebFrank100Frank2
915-FebFrank200Bill2
1015-FebBill250Mike0
1116-FebBob100
1216-FebBob110
1316-FebBob300
1416-FebBob310
1516-FebBob320
1616-FebBob200
1716-FebBob210
1816-FebFrank500
1917-FebBill100
2017-FebBill110
2117-FebBill300
2217-FebBill210
2317-FebBob300
2417-FebBob210
2517-FebBob100

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This is the way I would do it. Now, one of the MVP's probably has some really cool formula.....

Create a helper column that gives you the count of how many times a person has an entry per day in column D, Cell D4
=COUNTIFS(A$3:A3,A4,B$3:B3,B4)
Yes, I did want to include the headers in the formula. It counts how many previous instances of the combination name/date occurs.

In cell G7 put:
=COUNTIFS($A$4:$A$25,">"&$G$1-1,$A$4:$A$25,"<"&$G$2+1,$B$4:$B$25,F7,$D$4:$D$25,0)
and copy down

Jeff
 
Upvote 0
Here's one way:

Excel 2012
ABCDEFG
1Start date11/1/2017
2End Date2/17/2018
3DatePersonCode
415-FebBob100
515-FebBob110
615-FebBob300Days with an entry
715-FebFrank500Bob3
815-FebFrank100Frank2
915-FebFrank200Bill2
1015-FebBill250Mike0
1116-FebBob100
1216-FebBob110
1316-FebBob300
1416-FebBob310
1516-FebBob320
1616-FebBob200
1716-FebBob210
1816-FebFrank500
1917-FebBill100
2017-FebBill110
2117-FebBill300
2217-FebBill210
2317-FebBob300
2417-FebBob210
2517-FebBob100

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet6

Array Formulas
CellFormula
G7{=SUM(SIGN(FREQUENCY(IF($B$4:$B$25=F7,IF($A$4:$A$25>=$G$1,IF($A$4:$A$25<=$G$2,$A$4:$A$25))),$A$4:$A$25)))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



I changed all the dates in column A to be 2018, and I changed the G1 date too.

(And I do think it's kind of a cool formula! But the option in post 2 also works, and is probably simpler to understand and maintain.)
 
Upvote 0
Yup, Cool Formula!

So Eric, do you maintain a list of formulas in general categories just for this purpose? Or have you created similar formulas so often that you can pop them into a new format?

I used to think dynamic named ranges were magic until I understood how they worked. Now people look at me think I'm magic because I can remember that. I'm going to pick the formula apart as I have tried on similar "Array" formulas and try to understand it logically. It just doesn't appear, at first, to fall into a standard Excel Function format, so it seems foreign to me.

Jeff
 
Upvote 0
Eric C, THANKS! Works perfect. Exactly what I was looking for.

Jeff, thanks for your response as well, but I was looking for a solution without adding additional columns / steps.
 
Last edited:
Upvote 0
rjheibel, glad we could help! :)

Jeff, it's pretty much like you thought. When I started here, array formulas were a foreign language, and I didn't even know FREQUENCY existed, let alone how to use it in this context. But I picked apart anything that looked interesting until I figured it out, and after a while I could recognize when a certain formula would work in a given situation, and how to adapt it. I have a large library of links for useful information, but I don't refer to it as much anymore. I still look for interesting topics though.
 
Upvote 0
Eric,

Please let me know if my evaluation is correct.

The red part of the Formula (f) is normally the array you want to count. In this case, you have added nested if statements to check the person and date range.

The Blue part of the f is the date range as the part returned. Could this have been column B as well? Normally Excel would have given values down the column as a return, but in this case it returns an array of values instead of bins of data.

SIGN then returns any value above zero as 1 and any zero as zero.

Sum then counts all the 1's.

=SUM(SIGN(FREQUENCY(IF($B$4:$B$25=F7,IF($A$4:$A$25>=$G$1,IF($A$4:$A$25<=$G$2,$A$4:$A$25))),$A$4:$A$25)))

What is strange for me is that Frequency doesn't normally evaluate IF a value meets the criteria, it just returns Bins of data.
 
Upvote 0
Jeff,

No, you couldn't use column B instead of A. We want to find out how many unique days for each person, not how many unique people. As you noted, FREQUENCY puts numbers into bins. First, B is text, not numbers. We can get around that by using MATCH to convert them to numbers, but that still won't give us what we want. We want to make each bin represent one day, so that each bin will contain the number of times that day is used. Then the SIGN changes those values to 0s and 1s. It's convenient that dates are saved as numbers.
 
Upvote 0
Thank you. It's logical. I understand if I think about it. Now I need to use it on a regular basis so it becomes a wrote and modular tool.
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

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