yes, you can write a formula...typically they come in sets of 3.
1 in group header, which resets the value, like:
shared numbervar aSum:=0;
"" //hides the output of 0
1 in the group footer to display the value:
shared numbevar aSum
1 in the details that does the work:
shared numbervar aSum;
if {table.boolean} And {table.Change} <> Previous{table.Change} then
aSum := aSum + {table.ValueToSum};
"" //to hide the output (remove to debug)
if you get the general idea, so you should be able to modify as needed to suit your needs.
HTH