CountIf Function for Variable Date Range

ShaunF

Board Regular
Joined
Jan 17, 2015
Messages
54
Hi,

Am after a simple formula for counting the numbers of instances a date falls in the previous six months.

For example, I may have data that shows:

16/04/2014
18/02/2013
31/01/2014
04/02/2015
15/09/2014
03/01/2013
11/02/2015
27/08/2014
01/10/2015
12/04/2011
24/06/2015
00/01/1900
27/02/2015
13/10/2015

<colgroup><col></colgroup><tbody>
</tbody>

I want to count the number of times a date appears in the previous six months (from date of running the report). Assuming I ran the report on 13/10/2015, it should return a result of '3'.

Any assistance appreciated.

Thanks,

Shaun.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Perhaps this:

=COUNTIFS(A1:A14,">="&EDATE(B1,-6),A1:A14,"<="&B1)

Where B1 contains the date 13/10/2015.
 
Upvote 0
Hi Dreid1011,

Thanks for the suggestion. So my full formula is the below, however is returning a result of 0 which is not correct. Any ideas on where I may have gone wrong?

=(SUMPRODUCT(COUNTIFS(RJCP01!$T$2:$T$2000,KNX,RJCP01!$BS$2:$BS$2000,">="&EDATE(CI1,-6),RJCP01!$BS$2:$BS$2000,"<=CI1")))

Regards,

Shaun.
 
Upvote 0
At the very least, make the change highlighted below:

=(SUMPRODUCT(COUNTIFS(RJCP01!$T$2:$T$2000,KNX,RJCP01!$BS$2:$BS$2000,">="&EDATE(CI1,-6),RJCP01!$BS$2:$BS$2000,"<=CI1")))

to

=(SUMPRODUCT(COUNTIFS(RJCP01!$T$2:$T$2000,KNX,RJCP01!$BS$2:$BS$2000,">="&EDATE(CI1,-6),RJCP01!$BS$2:$BS$2000,"<="&CI1)))
 
Upvote 0
Sorry though still does not appear to work.

=(SUMPRODUCT(COUNTIFS(RJCP01!$T$2:$T$2000,KNX,RJCP01!$BS$2:$BS$2000,">="&EDATE(CI1,-6),RJCP01!$BS$2:$BS$2000,"<="&CI1)))

Thanks.
 
Upvote 0
Column T represents locations. There are around 170 locations grouped into 7 clusters. KNX represents one of the clusters.

So in essence, as a further example, when using the below data I am wanting to return the number of times a date occurs in Brisbane which falls in the previous 6 months. In this case '1'.

Column AColumn B
Sydney14/10/2015
Melbourne01/01/2015
Brisbane06/07/2015
Sydney06/06/2014
Sydney07/03/2015
Brisbane04/05/2014
Melbourne05/08/2013
Melbourne09/06/2015
Adelaide08/08/2015

<colgroup><col><col></colgroup><tbody>
</tbody>

Thanks,

Shaun.
 
Upvote 0
You should be able to do this without the SUMPRODUCT wrapped around your COUNTIFS.

Both of these worked for me:

=COUNTIFS(A1:A9,D2,B1:B9,">="&EDATE(D1,-6),B1:B9,"<="&D1)
=SUMPRODUCT((A1:A9=D2)*(B1:B9>=EDATE(D1,-6))*(B1:B9<=D1))

Where:
A1:A9 = Locations
B1:B9 = Dates
D1 = Target Date (13/10/2015)
D2 = Target Location (Brisbane)

Result = 1
 
Upvote 0
Thanks for your support. When using the exact example above I get a result of 0, instead of 1.

When using actual data I also get a result of 0.

Frustrating. Any ideas?
 
Upvote 0
I'm not sure. I had to changes your dates from dd/mm/yyyy to mm/dd/yyyy being on an American system. Other than that, the only thing I can think of is they are not recognized as actual dates.


I apologize for the delay in response, I was on vacation.
 
Upvote 0

Forum statistics

Threads
1,216,162
Messages
6,129,218
Members
449,494
Latest member
pmantey13

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