# Google spreadsheets—sum cells from another row based on a cell value

My current code is:

``````(SUM(INDIRECT(ADDRESS(ROW()-(I4:I- 1);COLUMN()-4;4)&":"&ADDRESS(ROW();COLUMN()-4;4)))*( ( J4:J ) / 10 ))))
``````

I want to sum cells from `Gx``Gy` but range is determed by cell `I4`. My existing code works, but only for one line.

``````=ArrayFormula( if( J4:J = "" ; "" ;
``````

So if I put `ArrayFormula` in front, the calculation is shown only where the data is, but the result is always equal to the result of first row.

Can anyone help me?

You can view my sheet here.

With the magic of matrix multiplication and this solution (credit where credit is due), I have managed to wrangle it to do what you want.

``````=ArrayFormula(IF( J4:J = "" ; "" ; MMULT((ROW(G4:G)>=TRANSPOSE(ROW(G3:G)))*((ROW(G4:G)+1-I4:I)<=TRANSPOSE(ROW(G3:G)));G3:G)* ( ( J4:J ) / 10 ) ))
``````

My head hurts already, so I won't go into too much explanatory detail, except to say that the key magic happens in

``````="MMULT((ROW(Range1)>=TRANSPOSE(ROW(Range2)))*((ROW(Range1)+1-I4:I)<=TRANSPOSE(ROW(Range2)));Range2)))"
``````

And I've added a second sheet to your public one with a rough equation builder, for understanding or alternative applications.

• You're welcome. And I'll make you deliver on that offer one day. Oct 8 '13 at 10:35