Try this Array Formula. Array Formula requires confirmation with Ctrl+Shift+Enter instead of just Enter.
In G5
=SUM(IF(FREQUENCY(IF($A$4:$A$22=F5,IF($C$4:$C$22>0,MATCH($B$4:$B$22,$B$4:$B$22,0))),ROW($A$4:$A$22)-ROW($A$4)+1),1))
and copy down.
Remember that an Array Formula is confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
Bookmarks