This formula, entered as an array formula with CTRL+SHIFT+ENTER, will return what you are looking for:
However, I had to alter how your month labels were displayed in Excel in order for the date criteria (cells X5 and Y5) to work correctly. The attached workbook should display the correct results, but I did not enter the formula because I was unsure of where you wanted it to go.
EDIT:
After re-reading your requirements, input the formula above into cell X19 as an array formula for the result you are looking for.
Bookmarks