I think it could look like this
if(peek(a) =a, peek(e)+c,c) as e,
if(peek(a) =a, peek(f)+d,d) as f
resident tab1 order by a ASC, b ASC;
i.e. order your Input table by a, b ascending (like in your example, but force it).
Check if first column value is identical to previous value, then sum up, else (first appearance of value) start with initial value.
I hope I understood your requirement,
You can see the attached example.
I hope is what you want.
Table.qvw 114.6 K