With some modification/transformation Jerry's formula will work when there is a blank in column A.
Using the setup in post #3, select cell G2 and paste the following array entered formula* into the formula bar:
Formula: copy to clipboard
=SUM(INDEX(($D$1:$D$12=F2)*(IFERROR(MATCH($A$1:$A$12,$A$1:$A$12,0),0)=ROW($A$1:$A$12)),0))
*After pasting the formula into the formula bar, activate the formula by simultaneously pressing Ctrl, Shift and Enter. You will then be able to copy the formula down.
Let us know if you have any questions.