Put this formula in D2, then copy down:
=IFERROR(INDEX($D$1:$D1, MATCH(A2&"-"&C2, INDEX($A$1:$A1&"-"&$C$1:$C1, 0), 0)), MAX($D$1:$D1)+1)


To remove the formulas
1) highlight the entire column D
2) Copy
3) Paste Special > Values