Supat,
here you go....
=SUM(IF(FREQUENCY(IF($A$2:$A$14<>"",
IF($A$2:$A$14=D2,MATCH("~"&$B$2:$B$14&"",$B$2:$B$14&"",))),
ROW($A$2:$A$14)-ROW($A$2)+1),1))
Cell D2 is where you define your search criteria (AB, LK, etc)
Increase the range as desired...
NOTE: This is a array formula, please...