The proposed solution won't work, because it does not aggregate.
You need a global variable and a custom function F with three parameters ($balance, $paid and $rank) to resolve this.
The custom function logic:
if ($rank = 1)
$GV = $balance;
else
$GV = $GV - $paid;
return ($GV);
In the mapping for new_balance specify:
F(balance, paid, rank)