[Solved] Count cells for a date range

Discuss the spreadsheet application
Post Reply
touchups
Posts: 2
Joined: Sat Sep 23, 2017 5:53 pm

[Solved] Count cells for a date range

Post by touchups »

I have a column of dates. Need to count the number of those date entries based on month and year only. Basically trying to see how many "widgets" sold per month per year. Thank you.
Last edited by Hagar Delest on Sun Sep 24, 2017 9:15 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.3, Windows 10
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Count cells for a date range

Post by acknak »

Greetings and welcome to the community forum!

If A1:A4 is the range containing the dates, and you wanted the number of dates in January of this year, something like this will work:
=SUMPRODUCT(A1:A4>=DATE(2017;1;1);A1:A4<=DATE(2017;1;31))

If you wanted to count dates that are in September of any year, maybe something like this:
=SUMPRODUCT(MONTH(A1:A4)=1)

The SUMPRODUCT here is just adding up zeroes and ones (the results of the boolean comparisons) to give a count; I used it instead of plain SUM out of convenience, since these are array formulas and SUMPRODUCT provides its own array context.
AOO4/LO5 • Linux • Fedora 23
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Count cells for a date range

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
thinman3
Volunteer
Posts: 382
Joined: Sat Jul 11, 2009 8:53 pm

Re: Count cells for a date range

Post by thinman3 »

If you wanted to count dates that are in September of any year, maybe something like this:
=SUMPRODUCT(MONTH(A1:A4)=1)
I think acknak had January on his mind( =1 ); instead of the 1 , use 9 for September.
3.4.1 & 4.1.5 on MS Windows 7 Pro x64
touchups
Posts: 2
Joined: Sat Sep 23, 2017 5:53 pm

Re: Count cells for a date range

Post by touchups »

Thank you for the replies. I kept working on it since my original post and came up with the sumproduct solution. Thanks again!
OpenOffice 4.1.3, Windows 10
Post Reply