Count negative values within date range (month)
I have values in a table like this
Date Values
01/01 5:35
02/01 -7:08
02/01 3:45
15/01 -4:05
02/02 3:25
13/02 4:25
19/02 6:20
I would like to count by month how many 'Values' are negative (i.e. contain a '-' character). I have tried a few things without success. Assume that the values in 'Date' column are real dates so I can use functions like month(). The values in 'Values' column are text (i.e. prefaced with ') as I can't get Excel to cope with negative times correctly.
=SUMPRODUCT(--(A2:A9999<>""),--(MONTH(A2:A9999)=1),IF("-*",B2:B9999))
I was hoping this How can I sum values within a specific time and date range? would help, but I couldn't adapt it for my circumstance.
Appreciate some advice.
You can't use wildcards when comparing with = so you need LEFT function in SUMPRODUCT formula like this
=SUMPRODUCT(--(A2:A9999<>""),--(MONTH(A2:A9999)=1),--(LEFT(B2:B9999)="-"))
That will count January dates in any year
In Excel 2007 it might be easier with COUNTIFS, assuming you have the start date of the month to count in D2 (e.g. 1/1/2012) then use this formula for January 2012 only
=COUNTIFS(A:A,">="&D2,A:A,"<="&EOMONTH(D2,0),B:B,"-*")
To count negative values you can use =COUNTIF(A1,"-*")
To count for a specific month =IF(MONTH(B1)=1,COUNTIF(A1,"-*"),0)
this will put a 1 for any negative value for month=1
(january). You can change the month = value
for your month and you will get a column of 1s and 0s when you drag it down column C
(helper column)
At the end of the helper column you can =sum(C:C)
to count the number of negative values for a given month
of if you want to calculate the sum of the negative values =SUMIF(C:C,"=1",A:A)
Basically, what we're doing is using a helper column in column C
. You can hide this column and do your =sumif
or =if
somewhere in Column D
if you don't want the helper column to show.
edit
Changed the countif
to count if it has a minus sign in it as the <0 won't work for non-numbers - should work