Counting distinct occurences between two columns based on date

SHUTTEHFACE

Board Regular
Joined
Aug 13, 2014
Messages
53
Hi All,

I'm using the below formula to try and calculate count of dates that are older than 90 days old between two columns (AK and AM). I want to make sure that should the value in AK AND the value in AM both be older than 90 days, they are only counted once.

<code>
Code:
=SUMPRODUCT(--('sheet1'!$B:$B="THC"),--('sheet1'!$AK:$AK<=TODAY()-90),--('sheet1'!$AM:$AM<=TODAY()-90),--('sheet1'!$E:$E={"1, THC Pilot","1, Both Pilot","2, THC Pilot","2, Both Pilot","3, THC Pilot","3, Both Pilot"}))
</code>
Can anyone assist?

Cheers,

STF
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Any ideas?

I'm getting a #value ! error with the current formula.

I'm trying to count all the dates in column AM and AK that are older than 90 days and also have "THC" marked in column B and one of {"1, THC Pilot","1, Both Pilot","2, THC Pilot","2, Both Pilot","3, THC Pilot","3, Both Pilot"} in column E.

thanks!
 
Upvote 0
Any ideas?
I would strongly recommend not using whole column references in a formula like this. You are asking for a very large number of calculations.

In my suggestion below, I have only used down to row 15 for testing, but instead choose a number big enough to cover the largest data you might have but not too huge. (eg 5000?)

Try a formula like this

Code:
=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),--ISNUMBER(SEARCH("|"&E2:E15&"|","|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|")))
 
Last edited:
Upvote 0
I would strongly recommend not using whole column references in a formula like this. You are asking for a very large number of calculations.

In my suggestion below, I have only used down to row 15 for testing, but instead choose a number big enough to cover the largest data you might have but not too huge. (eg 5000?)

Try a formula like this

Code:
=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),--ISNUMBER(SEARCH("|"&E2:E15&"|","|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|")))

Thanks! Would you mind explaining the last piece of the formula? I'm not quite following.

Cheers.
 
Upvote 0
Thanks! Would you mind explaining the last piece of the formula? I'm not quite following.
I assume that you mean the blue part below.
Rich (BB code):
=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),--ISNUMBER(SEARCH("|"&E2:E15&"|","|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|")))

It checks your extra requirement:
.. one of {"1, THC Pilot","1, Both Pilot","2, THC Pilot","2, Both Pilot","3, THC Pilot","3, Both Pilot"} in column E
It does so by joining all of those values in one string, delimited by the "|" (any character not in the list of values) so we get a single string:
"|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|"
The formula then puts the "|" character before and after each value in column E and checks to see if it can find those values in the string.
For example,
- if E2 is "2, THC Pilot" the formula would look (SEARCH) for "|2, THC Pilot|" in the red string above. That string is found starting at position 28 in the red string so the SEARCH function returns 28. So ISNUMBER is true so row 2 would be included in the count.
- if E3 is "abc" the formula would look (SEARCH) for "|abc|" in the red string above. It is not found so SEARCH returns an error so ISNUMBER is false so row 3 would not be included in the count.

Hope that clarifies for you (it's usually easier to write the formulas than explain them :)).
 
Upvote 0
I assume that you mean the blue part below.
Rich (BB code):
=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),--ISNUMBER(SEARCH("|"&E2:E15&"|","|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|")))

It checks your extra requirement:
It does so by joining all of those values in one string, delimited by the "|" (any character not in the list of values) so we get a single string:
"|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|"
The formula then puts the "|" character before and after each value in column E and checks to see if it can find those values in the string.
For example,
- if E2 is "2, THC Pilot" the formula would look (SEARCH) for "|2, THC Pilot|" in the red string above. That string is found starting at position 28 in the red string so the SEARCH function returns 28. So ISNUMBER is true so row 2 would be included in the count.
- if E3 is "abc" the formula would look (SEARCH) for "|abc|" in the red string above. It is not found so SEARCH returns an error so ISNUMBER is false so row 3 would not be included in the count.

Hope that clarifies for you (it's usually easier to write the formulas than explain them :)).

Thanks! I don't think the formula is quite doing what I want it to.

Here is what the output should return:


Data more than 90 days old
Data less than 90 days old
THC pilot75

<colgroup><col style="width:48pt" width="64"> <col style="mso-width-source:userset;mso-width-alt:2121;width:44pt" width="58"> <col style="width:48pt" width="64"> </colgroup><tbody>
</tbody>


Data Sample

group
Priority
Received
Final approval
THC3, THC Pilot4/17/20188/8/2018
THC1, THC Pilot8/7/20178/8/2018
THC2, Both Pilot
THC1, Both Pilot9/25/20178/8/2018
THC1, Both Pilot8/15/20178/8/2018
THC3, Both Pilot9/18/2017
THC1, Both Pilot8/15/2017
THC1, THC Pilot7/6/2017
THC1, THC Pilot8/28/20173/20/2018
THC1, Both Pilot8/15/2017
THC1, Both Pilot7/11/20171/20/2018
THC1, Both Pilot9/25/2017
THC2, Both Pilot7/20/20188/8/2018

<colgroup><col style="mso-width-source:userset;mso-width-alt:2157;width:44pt" width="59"> <col style="mso-width-source:userset;mso-width-alt:2998;width:62pt" width="82"> <col style="mso-width-source:userset;mso-width-alt:2486; width:51pt" width="68" span="2"> </colgroup><tbody>
</tbody>


Cheers,

STF
 
Upvote 0
I can't see how this relates to your original formula & description at all. :confused:
 
Last edited:
Upvote 0
I can't see how this relates to your original formula & description at all. :confused:

=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),--ISNUMBER(SEARCH("|"&E2:E15&"|","|1, THC Pilot|1, Both Pilot|2, THC Pilot|2, Both Pilot|3, THC Pilot|3, Both Pilot|")))where group = b2:b5
Received = ak2:ak15Final approval = am2:am15
Priority = e2:15

Cheers,

STF
 
Upvote 0
Any ideas? Hoping to get this working soon :(

Also tried to simplify but still not working
Code:
=SUMPRODUCT(--(B2:B15="THC"),--(AK2:AK15<=TODAY()-90),--(AM2:AM15<=TODAY()-90),[COLOR=#0000CD]--(E2:E15="*Pilot*")))[/COLOR]
 
Upvote 0
Also tried
Code:
=SUMPRODUCT(--(ISNUMBER(SEARCH("THC",$B:$B))),--(ISNUMBER(SEARCH("*Pilot*",$E:$E))),--($AK:$AK>0),--(DATEDIF($AK:$AK,TODAY(),"d")+1<90),--($AMO:$AM>0),--(DATEDIF($AM:$AM,TODAY(),"d")+1<90))

But am getting # value error
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

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