# Increment value based on condition

I'm trying to combine arrayformula with an increment value based on a condition.

Basically I have a column called purpose, it basically has 2 values - Restock and Order. Upon order, column Count Order will display 1, otherwise, 0. On the column over, without arrayformula I'd add the row above with the value on the left, example

``````Purpose | Count Order | Increment
Restock | 0           | 0
Order   | 1           | 1
Restock | 0           | 1
Order   | 1           | 2
``````

I'd normally use the code for C2=B2, then the subsequent line would be C3=B3+C2

With arrayformula, my formula that I came up with was

``````={"Increment"; arrayformula(if(A2:A="","", (B2:B)+(C1:C)))}
``````

Which gives me a circular error. I'm guessing in part I'm trying to add the header which the only thing I can think of is have this array start on.

Is there a better way than to start lower with this formula? Apologies, looks like there's a bit of discrepancy after I simplified my question.

I put the formula provided into my spreadsheet for cell E1, header fills, first row is empty because of the pivot (which if I remove, after I add new data, it doesnt check off the new data and the (blank).

I'm thinking instead of pivot do I need to write a query utilizing distinct for the timestamp and purpose columns, would that resolve my issue with the blank and the increment?

``````={"Increment"; arrayformula(if(B2:B="","", sumif(row(B2:B),"<="&row(B2:B),B2:B)))}
• @FelixPau You should delete your answer that is not an answer but a question, here is one way to solve your issue of data being on row 3 instead of row 2 `={"Increment";""; arrayformula(if(B3:B="","", sumif(row(B3:B),"<="&row(B3:B),B3:B)))}` – CodeCamper Dec 15 '19 at 1:43