Try this:
in B4 put this formula:
=IF(B2="Team1",IF(B3
Then then copy it till AJ4.
Then in AK3 put this formula:
=COUNTIFS($A$2:$AJ$2,"Team1",$A$4:$AJ$4,1)
Similarly in AL3 put this formula.
=COUNTIFS($A$2:$AJ$2,"Team2",$A$4:$AJ$4,1)
Hope this approach works for you.