Answers

We can pass group name to the custom code, if the group name not changed, then Counter=Counter+1, otherwise, reset counter to 1. The custom code would like below.

dim shared Counter as integer=0
dim shared Group as String
public function getGroupCounter(GroupName as String) as Integer
If Group=GroupName Then
Counter=Counter+1
Else
Counter=1
End If
Group=GroupName
return Counter
end function

Then use the expression below to get the counter
=Code.getGroupCounter(Field!Group.Value)