Number items in a grouped view, resetting counter with each group
You can use the HTML List format. In the settings of this format, you can set the grouping field and then set the list to an ordered list.
By doing this, you won't need any global counter.
See in the following screenshot how the list would be rendered.