Subscribe Bookmark RSS Feed

Running summation of a column

new-jmper

Community Trekker

Joined:

Jun 23, 2011

So I have a column in the data table and want to generate a new column with the value the summation of the first column to the current row. For example:

C1     C2

1          1

0          1

1          2

1          3

0          3

Summation(i=1,Row(),:C1  works, but it is quite wasteful and slow for long columns.

Match(Row(), 1, :C1, Lag(:C2, 1) + :C1) works well so far, even the treatment of the first row is again wasted for the other million rows.

Is there a built-in function for this? Any better ways?

Thanks,

Dong

1 REPLY
peterw

Community Trekker

Joined:

Mar 28, 2013

try this formula:

If( Row() == 1,

:Column 1,

Lag( :Column 2, 1 ) + :Column 1

)

In row 1, it copies the value from column 1

for all other rows, it looks at the previous value in the same column 2, and adds the value from column 1 in the current row