You can use this "array formula" in L2
=SUM(IF(FREQUENCY(IF(A$2:A$6000=K2,IF(B$2:B$6000<>"",MATCH(B$2:B$6000,B$2:B$6000,0))),ROW(B$2:B$6000)-ROW(B$2)),1))
confirmed with CTRL+SHIFT+ENTER so that curly braces like { and } appear around the formula in the formula bar.....and copied down the column......it's a "resource hungry" formula so may take a few minutes for all rows to calculate.
regards, barry