COUNTIF with Dates(Month) - excel

I'm trying to count rows where the date in a Date column falls within a particular month. I've tried many paths but all result in an error in my formula. They boil down to me trying to do this:
=countIF(Month(SHData[#MS550]),MONTH(SHData[#MS550]))
My final formula will need to be more complex than that, but even something as simple as the above generates an error. I've also tried it with Text(Date,"MMMM") with the same results.

Would be easier with COUNTIFS but with COUNTIF you might count all the entries greater than or equal to the start of your chosen month, then subtract from that the count of all the entries after the end of your chosen month. Something like:
=COUNTIF(SHData[MS550],">42004")-COUNTIF(SHData[MS550],">42036")
for January this year, if using the 1900 date system.

Try using SumProduct, this just worked fine for me with a column of dates testing if they were in September:
=SUMPRODUCT(--(C3:C5>0),--(MONTH(C3:C5)=9))

Related

Counting the matches of a date in time periods in Excel

I am trying to find a (reasonably elegant) formula to find out how often a date appears in a list of date ranges.
In my example I have 4 date ranges, defined by a start date (A2:A5) and by an end date (B2:B5). Below I have a list of dates for which I would like to know how often a date appears in any of those 4 ranges. The only solution I came up with was to check for each range if the date is in there. The formula becomes quite lengthy with the number of periods and is not flexible if more periods are added later.
Here the time periods:
And here where I try to retrieve the number of matches given a date:
My formula is here for B11 (yielding 3 given the input of 10/Sep/2021):
=IF(AND($A11>=$A$2,$A11<=$B$2),1,0)+IF(AND($A11>=$A$3,$A11<=$B$3),1,0)+IF(AND($A11>=$A$4,$A11<=$B$4),1,0)+IF(AND($A11>=$A$5,$A11<=$B$5),1,0)
Any ideas appreciated!
Using COUNTIFS:
=COUNTIFS($A$2:$A$5,"<="&A11,$B$2:$B$5,">="&A11)

Find minimum date in row with multiple data types in Excel

I am trying to find the minimum date in a row that has both dates and number data types. I tried to use the MINIFS function but that still produces the number value as the minimum, rather than the date. I am restricted to doing this as an in-cell function, rather than in VBA. Also, the data structure is a bit wonky, I know, but it can't be changed.
=MINIFS(A2:C2,A2:C2,CELL("format",A2:C2)="D4")
When I enter =MIN(IF(A6:C6>40000,A6:C6)) I get a #Value error. Excel doesn't like the range before the > symbol.
Remember that dates in Excel are calculated as number of days starting from January 1st, 1900.
Thus, if you look at your dates as numbers, you will see that it's in fact a number '44042'.
Knowing that, you can use MIN together with IF formula:
=MIN(IF(B5:D5>43831,B5:D5))
Where your suggested numbers are in cells B5:D5 and '43831' is 2020/01/01.
Of course, if you have numbers with high values, this solution should be adapted.
Here's a screenshot I made:
img

Excel - Refer to column/range with Networkdays

=COUNTIFS(NETWORKDAYS(C:C, TODAY(), 1),">=" & 5)
I am trying to use something like the above to count any values in Column C (Date column of my dataset) where the working days from then to todays date is greater than 5. Can this be done without creating a working days column?
It's actually not so obvious but NETWORKDAYS does not work with ranges. Arrays however are completely fine. See this post on SuperUser too.
So in your case you could simply use:
=SUMPRODUCT(--(NETWORKDAYS(C:C+0,TODAY())>=5))
Obviously it's better not to reference the whole of column C. Depending if one has Excel O365, you could also just use =SUM instead of =SUMPRODUCT.

Excel SumIF dates in another cell are from previous month

I have a table of mortgage loans in Excel. I want to sum the loan amounts(B:B) for loans whose lock dates(D:D) were in the previous month. I am trying to use the "SumIF" function to pull criteria from a different cell as below:
=SUMIF(range,"*"&A1&"*",sum_range)
But I want to pull a "date between previous month start and previous month end" range. I've used this for another function and it has worked.
D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1
Now, I am trying to infuse the latter function into the first, something like this, but it is not returning anything. Any help would be much appreciated!
=SUMIF(Data!D:D,"*">="&EOMONTH(TODAY(),-2)+1,Data!D:D,"<"&EOMONTH(TODAY(),-1)+1)*",Data!B:B)
Use SUMIFS when you have multiple criteria, and from your explanation, it seems like you don't need the wildcard "*".
=SUMIFS(B:B,D:D,">="&EOMONTH(TODAY(),-2)+1,D:D,"<"&EOMONTH(TODAY(),-1)+1)

Sumif Amounts Based on Months for Multiple Months

I have excel data in the following format
Date Amount
01-Jan-16 23.94
12-Jan-16 17.96
26-Jan-16 32.92
03-Feb-16 38.90
20-Feb-16 62.27
26-Feb-16 45.89
I would like to sum the amount field for specific months, that is I would like to sum up the amount in January and also in February separately.
This is the code I have tried thus far which I found in a previously asked question (see Excel Formula to SUMIF date falls in particular month).
=SUM(IF(MONTH(A:A)=1,B:B,0))
It works for January but when I change 1 to 2 it returns zero.
=SUM(IF(MONTH(A:A)=2,B:B,0))
Would sumifs work better?
Here are two other ways of doing it:-
=SUMPRODUCT((MONTH(A2:A10)=1)*B2:B10)
and
=SUMIFS(B2:B10,A2:A10,">="&DATE(2016,1,1),A2:A10,"<"&DATE(2016,2,1))
Change as necessary to get totals for other months.
I have put the results next to the original array formula in this screen shot:-
Use specific range rather than full column. You must use the formula as array formula.
=SUM(IF(MONTH($A$2:$A$1000)=1,$B$2:$B$1000,0))
Press CTRL+SHIFT+ENTER to evaluate the formula as array formula.

Resources