title: 'Arrayformula' which references values in cells above, within array column?
body: <p>I'm attempting to array formula so that specific values from future Forms responses will be calculated automatically. Unfortunately, the formula uses the value in the above cell in the same column to return a running total, and I can't figure out how to turn it into an array without running into circular dependency errors, or having the formula break down and stop working properly.</p>
  
  <p><a href="https://i.stack.imgur.com/9tYoP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9tYoP.png" alt=""></a></p>
  
  <p>The formula in A1 takes all my unique product SKUs from a pivot table,
   transposes them across the top row, and adds three columns between them:</p>
  
  <p>A1: <code>=(SPLIT(JOIN("|"&amp;rept("|",3),TABLE!A2:A),"|",1,0))</code></p>
  
  <p>The formula in A2, E2, etc. queries my Live Form responses (DATA!) for the item SKU, returning timestamps, actions, and quantities for each form response relating to that SKU:</p>
  
  <p>A2 <code>=query(DATA!$A:$D,"select A,C,D where (B="&amp;A1&amp;") and C&lt;&gt;'SUBTRACT'",1)</code></p>
  
  <p>My problem arises in trying to make an array out of the formula in D3. This column is meant to give a running tab of the current number of pieces of stock which are "reserved" for upcoming jobs. As the stock is "ADD"ed, the reserve qty is satisfied and decreases, to a minimum of 0:</p>
  
  <p>D3 <code>=if(B3="RESERVE",D2+C3,if(and(B3="ADD",C3&gt;D2),D2-D2,D2-C3))</code></p>
  
  <p>This formula gives me the desired results and works if I click and drag it down to copy it into below cells in the same column, but I'd really like it to automatically apply new form responses add data to additional rows.</p>
  
  <p>My clumsy attempt at a fix, based on my limited experience with <code>ARRAYFORMULA</code> only returns <code>RESERVE</code> values as-is, and an error message:</p>
  
  <pre><code>=arrayformula(if(F3:F="RESERVE",H2:H+G3:G,if(and(F3:F="ADD",G3:G&gt;H2:H),H2:H-H2:H,H2:H-G3:G)))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yRqr5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yRqr5.png" alt=""></a></p>
  
  <blockquote>
    <p>Error. Array arguments to GT are of different size.</p>
  </blockquote>
  
  <p>Could someone please help me figure it out?</p>