Auto Increment Number based on other field values

Auto Increment Number based on other field values

I was curious if there was a way to Auto Increment Number based on the values of another field?

For example, If Field 1 =A and Field 2 =B then increment by 1 based on the amount of entries containing 'A' and 'B'…

So if I have 32 records where Field 1 =A and Field 2 =B, then the next record I add which has A and B will increment to 33

If i then make another record after that one, that has Field 1=J and Field 2=B, and I have no previous records that have those conditions, the auto number will display 1 because its the first entry with those settings. 

Curious if this is possible at all?