Try: if ([Exec P&L Heading]<>'incomes', fabs(RangeSum(Above(sum(Amount)),1,RowNo()))-fabs(sum(Amount)), 0). The 1 instead of the 0 will prevent using the Amount of the current row in the calculation of the offset too. You want only the sum of all the previous values.