In your formula you need to check the ID value to see if it has changed from the previous row and reset your index if it has.
Try this formula:
If(:ID != Lag(:ID, 1) | Row() == 1, 1, Lag(:IDIndex, 1) + 1)
Your ID Count column has use IDIndex to get its value:
Col Maximum( :IDIndex, :ID )
The second argument to the Col Maximum function is the By variable.
I hope that helps!
-Jeff
-Jeff