Excel limitations in functions for working out SUMS

https://preview.redd.it/ra3yw7kaajhe1.jpg?width=964&format=pjpg&auto=webp&s=b17d8a0e97da6f8ab24f3445fd63f18cf0f33c07

Count Items and fill in E3:H5 in the attached spreadsheet with count from data in column A and B.

Cannot figure out a formula