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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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
Hi. I inserted the new formula but it now returns #VALUE .

[TABLE="class: grid, width: 591"]
<tbody>[TR]
[TD]date[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]2017-01-01[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]2018-01-01[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2017-01-02[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2017-01-07[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]2017-02-05[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

L1 contains the formula:

=COUNTIFS(D:D,">="&K1,D:D,"<="&EOMONTH($K1,0))
 
Last edited:
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,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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