Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

8 Replies
Sokkorn
Master
Master

Hi Oronzo,

Your expression

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

Not applicable
Author

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

C=A+C(n-1)

Thanks

swuehl
MVP
MVP

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)

Not applicable
Author

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

test.PNG

swuehl
MVP
MVP

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?

Not applicable
Author

Thank you for your answer,

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

Many Thanks

Oronzo

swuehl
MVP
MVP

In the script, I would do it like this:

Result:

LOAD n, A, B,

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

resident YourTable order by n;

drop table YourTable;

where YourTable is the Input table already loaded with fields n,A,B.

Regards,

Stefan

Not applicable
Author

Thanks for your answer, I must analyze well my data

Regards

Oronzo