So I have the following situation:
In the first column I have certain values, in the second column, given a certain row, I want it to contain the result of a function applied to all the preceeding rows (plus itself) in the 1st column. In this case the function applied is SUM()
.
The dumb approach is the one I used: write the formula in the first row, then copy&paste down till the row you want the function to be applied to.
I want it to be automated, though, and function with as many rows in the given column as there are, even if they are removed or added. I thought I'd use ARRAYFORMULA()
for this, or MMULT()
combined with TRANSPOSE()
as I've seen doing in apparently related examples, but after quite a few tries I'm lost.
Does anybody know how it can be done?
Best Answer
The following Google Apps Script (GAS) will achieve your goal automatically:
Add this script, via the script editor, to your spreadsheet and the function CUMSUM is available throughout the worksheet, like so: =CUMSUM("A2:A8"). Because an array is returned, use
TRANSPOSE
to get the right positioning.See example file I've created: running total