depends on how the report is being done, but here a general outline of how to do it.
In the start of the group you want a formula that will set you variables =0
in the detail section, a formula that will increment the variables accordingly, and in the report footer, you can now access the variable and do any math that you need or you can display.
Sample formulas
in a group header
shared numbervar aVar := 0;
"" //suppresses the display of the 0
in a group footer
shared numbervar aVar
in a detail
shared numbervar aVar;
if {table.field} = someValue then
aVar := aVar + incrementAmount;
""//hide the results of the formula
HTH