Action to count tag value occurences?

I want an Action to add to the end of Artist a number indicating the quantity of tracks in the current operation that have that same value of Artist.

E.g. before, Artist is
A
A
A
B
C
C

After, it is:
A 3
A 3
A 3
B 1
C 2
C 2

Any ideas on how to achieve this? Thanks.