3 Replies Latest reply: Jul 21, 2011 12:47 PM by Robson Silva

# Cumulative Sum in Load

I need to do a cumulative sum in the resident table as follows

tab1

a, b, c, d

a, 201101, 1, 0

a, 201101, 1, 1

a, 201102, 1, 1

b, 201101, 1, 0

b, 201102, 1, 1

c, 201101, 1, 0

c, 201102, 1, 0

result

a, b, c, d, e, f

a, 201101, 1, 0, 1, 0

a, 201101, 1, 1, 2, 1

a, 201102, 1, 1, 3, 2

b, 201101, 1, 0, 1, 0

b, 201102, 1, 1, 2, 1

c, 201101, 1, 0, 1, 0

c, 201102, 1, 0, 2, 0

• ###### Re: Cumulative Sum in Load

Ri Robson,

I think it could look like this

Load *,

if(peek(a) =a, peek(e)+c,c) as e,

if(peek(a) =a, peek(f)+d,d) as f

resident tab1 order by a ASC, b ASC;

i.e. order your Input table by a, b ascending (like in your example, but force it).

Check if first column value is identical to previous value, then sum up, else (first appearance of value) start with initial value.

I hope I understood your requirement,

Stefan

• ###### Re: Cumulative Sum in Load

Hi Robson,

You can see the attached example.

I hope is what you want.

Best regards.

• ###### Re: Cumulative Sum in Load

Thanks guys!