Formula Help please!

Stejam

New Member
Joined
May 10, 2017
Messages
5
Hi. I have a set of dates in column D and I have this formula that counts the volume for each month from the whole column, it works great, but for January it returns 9999? Please can anyone figure out why?

=SUMPRODUCT(--(MONTH(D1:D10000)=1))

If you change the last number to 2 or 3 or 4 etc etc it counts February, March, April occurences etc etc but as I say with 1 in there for January it returns 9999?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi. I have a set of dates in column D and I have this formula that counts the volume for each month from the whole column, it works great, but for January it returns 9999? Please can anyone figure out why?

=SUMPRODUCT(--(MONTH(D1:D10000)=1))

If you change the last number to 2 or 3 or 4 etc etc it counts February, March, April occurences etc etc but as I say with 1 in there for January it returns 9999?
The problem is all of the blank cells in the range. When you apply the MONTH function to a blank cell, Excel converts the blank to the number 0 and uses that as the day number with the start year (1900) and start month (January)...

DATE(1900,1,0) ===> 1/0/1900

Hence, the MONTH function evaluate the month for 0 as 1... your formula is counting all the blanks in the column as being Janary. You need to add a test to your formula to make it work correctly...

=SUMPRODUCT(--(MONTH(D1:D10000)=1),--(D1:D10000<>""))
 
Last edited:
Upvote 0
Better to include the year too in your test, unless irrelevant...

=COUNTIFS(D:D,">="&K1,D:D,"<="&EOMONTH($K1,0))

where K1 houses a first day date like 2017-01-01.
 
Upvote 0
The penny has dropped now guys, thanks for explaining Rick how this formula actually works...I got this to work from your explanation and logic.

=SUMPRODUCT(--((MONTH($A$2:$A$50)=1)-($A$2:$A$50="")))

It was asked by another user and I now see how this works.
 
Upvote 0
The penny has dropped now guys, thanks for explaining Rick how this formula actually works...I got this to work from your explanation and logic.

=SUMPRODUCT(--((MONTH($A$2:$A$50)=1)-($A$2:$A$50="")))

It was asked by another user and I now see how this works.

Then it should be rather:

=SUMPRODUCT((MONTH($D$2:$D$50)=1)-($D$2:$D$50=""))

not what you have.

By the way, this will deliver 3 for the sample I posted. Is that what you want: count in all Januaries, irrespective the years they belong to?
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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