difference between two columns

Hi, I have a very simple cashflow grid.
I have the app grouped by type and two colums with totals, and I need the difference between the colums in each group, I mean, for example

Group -> 1

… … … 5 7
… . … … … 4 8
total 9 15
dif -6
Group -> 1

… … … 10 5
… . … … … 11 8
total 21 13
dif 8

Well, the thing is that I can’t do it. I don’t know how. I try to use this code in OnGroupByAll event

$dif = {total_column1_sum} - {total_column2_sum};
echo $dif; //just to see what happens

And I obtain the total of the difference (in my example above, 2), but not by group just the total (I attached an image with the example)

What’s wrong? There is another way to do that?

Thanks in advance.

Regards.

Q.

PS: sorry for my bad english

grid.jpg