ArrayFormula of Resetting Running Total in Google Sheets

Solution 1:

In addition, you could also try

=ArrayFormula(if(len(A:A),mmult(--transpose(if( (transpose(row(A:A))>=row(A:A))*(A:A=transpose(A:A)),B:B, 0)),row(A:A)^0),))

This should also work if the data is unsorted.

enter image description here

Solution 2:

If the table is always sorted on column A, you can just do:

=ARRAYFORMULA(SUMIF(ROW(B1:B6), "<="&ROW(B1:B6), B1:B6)-SUMIF(A1:A6, "<"&A1:A6, B1:B6))

enter image description here

If the table is not sorted, you can still do it with a vlookup:

=ARRAYFORMULA(SUMIF(ROW(B1:B6), "<="&ROW(B1:B6), B1:B6)-SUMIF(row(A1:A6), "<"&vlookup(A1:A6,{A1:A6,row(A1:A6)},2,false), B1:B6))

enter image description here