# Cumulative Sum without Script

For this question, I've created a Google Apps Script function, that calculates the cumulative sum of a range. Martin Hawksey on Google+ made a comment about a more efficient way of calculating the cumulative sum:

``````function cumulativeSum(array){
var output = [];
for (i in array){
if(i==0) {
if (array[i].length > 1) throw ("Only single column of data");
output.push([array[i]]);
} else {
output.push([output[i-1] + array[i]]);
}
}
return output;
}
``````

My question is: can this be achieved with the usage of formula's?

• Apologies for a very late answer, I just saw he thread in "Related" on the right. Jun 30 '13 at 10:22

Yes:

`=ArrayFormula(SUMIF(ROW(A1:A10);"<="&ROW(A1:A10);A1:A10))` The numbers in the green circle are the ones being summed, the ArrayFormula is populating all the others based on the cell it was pasted into, in this example I pasted in A11, B1, and C1 to show its effect.

This spreadsheet that I made a while ago attempts to explain how MMULT can be used for these sort of problems, and it also demonstrates the SUMIF solution on one of the sheets, which can (and probably should) be used for special cases like the one in this question.

• I took this formula once (I think it was yours) on the Google Forum: SUMIF(ROW(A:A);"<"&ROW(A:A)), that didn't work. This one does. Jun 30 '13 at 11:56
• The image in the answer was edited in by another member: +Xavier Casto Jul 4 '13 at 0:10
• @Fogest, I used a product called "Snagit" find out more about at techsmith.com/download/snagit Jul 5 '13 at 15:49
• @XavierCasto Oh, I've used this a LONG time ago, didn't remember it having this, though it was a long time ago. Thanks for the reply though, I like products by techsmith. Jul 5 '13 at 15:50

Assuming you want:

``````  Row | A | B | B's formula
--------------------------------
1  | 1 | 1 | =1     (or =A1)
2  | 2 | 3 | =1+2   (or =A2+B1)
3  | 3 | 6 | =1+2+3 (or =A3+B2)
``````

etc...

Then you can use:`=sum(\$A\$1:A1)` where `A1` is the start of numbers to sum. Put that formula in `B1` (or where ever you want) and fill it down, and it will sum all cells up to and including the row you're on. Alternately, you can use the `=Ax+Bx-1` (x = current row, data in A, cumulative sum in B) format from the "B's formula" section above.

• This seems to work and is much simpler than the accepted answer Mar 15 '17 at 6:18
• agreed, this is simpler and it works seamless! May 29 '18 at 21:40

The accepted answers are far too complicated for running tallies. A much easier answer is:

``````=SUM(A\$1:A1)
``````

Substitute the `A` for the column you want. Substitute `1` for the row you want. Click the small box in the bottom right corner of the cell and drag it down to auto tally the cells you chose. Note: I know when this was asked that my solution might not have been available but in 2020 the title 'Cumulative Sums without Scripts' makes this a leading google result for the query 'running totals in google sheets' and all the Google results had long complicated answers.

While the accepted answer is on spot it has a major disadvantage due to the fact that the last parameter of `SUMIF` needs to be always a "valid range" so when it comes to some more advanced running total calculation `MMULT` is the better option:

``````=ARRAYFORMULA(IF(LEN(A1:A),
MMULT(TRANSPOSE((ROW(A1:A)<=TRANSPOSE(ROW(A1:A)))*A1:A), SIGN(A1:A)^2), ))`````` 