I'm using a SUMIFS on Excel. One of my range columns is filled with dates formatted as "YYYY-MM". I want to sum only the values of another column that correspond with specific years, inclusive of all months. So for instance, I may have 2000-05, 2000-06, etc, and I wanna sum all the values that have "2000-" in them, no matter the MM value. Is there a way to do this?
0
votes
2 Answers
2
votes
Assuming your data are in cells A1:A23
, you can use the below to find the number of dates that are of the year 2000.
{=SUM((YEAR(A1:A23&"-01")=2000)*1)}
Note the curly brackets {}
indicate that you must press cntrl+shift+enter
when you finish typing the formula. (This is because it is an array formula).
The logic here is that A1:A23&"-01"
will convert all the dates in those cells from, for example 2000-05
to 2000-05-01
. Then the YEAR()
function recognises this as a date and returns 2000
.
The =2000
bit will return an array of booleans for example
TRUE
TRUE
TRUE
FALSE
FALSE
TRUE
We multiply this array by 1 to get
1
1
1
0
0
1
And we sum this to get the count of numbers with year = 2000.