no one can tell you the formula, we don't know the data or the report.
I would use variables and every time a detail line is printed, I would check the time stamp and determine which bucket(variable) to increment.
that would be the basis of the report changes that you requested. Then in the group footer or whichever footer you want, I would reiterate the current values of the variables and reset them as needed. There may be a whole host of variables tracking different groupings data and being updated/reset as needed.