8 Replies Latest reply: Dec 22, 2011 4:34 AM by Oronzo Lezzi

# recursive sum

ThanksHello to everybody

I need to have a calculate columns starting from 2 columns

A
BCn
01001001
2001202
3001503
1001604
1001705

if A=0

C=B

if  A <> 0  C=A+C(n-1)

I have tried an Expression like this

if(A=0, B,rangesum( A,above(C,0,RowNo()) ) )

but it doesn't works.

Does anyone have any suggestions for me?

Thanks

Oronzo

• ###### recursive sum

Hi Oronzo,

if  A <> 0  C=A+C(n-1)

Can use this if  A <> 0  then C=A/(2-n) ?

If like this it easy to calculate value.

Regards,

Sokkorn Cheav

• ###### recursive sum

My goal is to have the sum of A with the previous value of C (  C(n-1)..)

C=A+C(n-1)

Thanks

• ###### recursive sum

Not sure if this fulfills all your requirements, but with the given sample, this results in the expected values for C:

=aggr( rangesum(above( A,0,RowNo()))+ rangesum(above( B,0,RowNo())),n)

• ###### Re: recursive sum

Hello

Thank you for your answer, but is not exactly what I would to obtain

In attachement I have put an example

With this expression

if(A=0,B,aggr( rangesum(above( A,0,RowNo()))+ rangesum(above( B,0,RowNo())),n))

regard

• ###### Re: recursive sum

Yes, I already thought you would like to reset the overall value on zero values in field A, i.e. you have multiple segements that you want to sum up separately, right?

Can this be done in the script? Would be much easier then, or do you need to be sensitive to selections?

• ###### Re: recursive sum

But since I use QlikView just need to know how to load the script.

Many Thanks

Oronzo

• ###### Re: recursive sum

In the script, I would do it like this:

Result:

if(A=0, B, A+ peek(C)) as C

resident YourTable order by n;

drop table YourTable;

Regards,

Stefan