Resolution:
Refer to the chapter Report Writer in the Language Reference - Additional Topics for the rules governing the resetting of sums. Revise your code accordingly.