Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
jduluc12
Creator
Creator

if, peek and rangesum in script

Hi,

I have data like this.

ItemIncrDecr
A10
A21
A31
B40
B21
B53

 

I want to a running total for each item and the output should look like this

ItemIncrDecrRunningTotal
A101
A21(1+2) - 1 = 2
A31(2+3) - 1 = 4
B404
B21(4+2)-1 = 5
B53(5+5) - 3 = 7

 

ItemRunningTotal:
Load Item, incr, decr

if (peek(Item) = Item, rangesum(peek(RunningTotal), Incr, -Decr)) as RunningTotal

Resident Item;

Is it correct?

Thanks

Labels (1)
1 Solution

Accepted Solutions
Frank_Hartmann
Master II
Master II

Try like this:

tmp:
LOAD Item, 
     Incr, 
     Decr
FROM
[https://community.qlik.com/t5/QlikView-App-Dev/if-peek-and-rangesum-in-script/td-p/1781908]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

NoConcatenate


Final:
LOAD *,
If(Item=Previous(Item), RangeSum(Peek('RUNNING_TOTAL'), Incr-Decr), Incr-Decr) as RUNNING_TOTAL 
Resident tmp Order By Item, Decr; DROP table tmp;

View solution in original post

1 Reply
Frank_Hartmann
Master II
Master II

Try like this:

tmp:
LOAD Item, 
     Incr, 
     Decr
FROM
[https://community.qlik.com/t5/QlikView-App-Dev/if-peek-and-rangesum-in-script/td-p/1781908]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

NoConcatenate


Final:
LOAD *,
If(Item=Previous(Item), RangeSum(Peek('RUNNING_TOTAL'), Incr-Decr), Incr-Decr) as RUNNING_TOTAL 
Resident tmp Order By Item, Decr; DROP table tmp;