Alberto,
In such cases I usually:
- Create a function which defines and initializes a global variable to 0.
- Place this function in the group header
- Create a function which increments the global variable
- Place this function in the details section
- Change the coloring function to use the global variable instead of the special field