Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
scotly-victor
Creator II
Creator II

RangeSum Issue

Hi Every One,

I  wanted  a Rangesum of Qty by Itemcode ,Branch.

Input:

LOAD * Inline [

Date,Itemcode,Branch,Qty

1/1/2013,A,112,7

1/1/2013,A,112,14

3/1/2013,A,113,10

4/1/2013,A,112,23

5/1/2013,B,112,23

5/1/2013,B,112,24

];

Desired Output:

LOAD * Inline [

Date,Itemcode,Branch,runningQty

1/1/2013,A,112,7

1/1/2013,A,112,21

3/1/2013,A,113,10

4/1/2013,A,112,44

5/1/2013,B,112,23

5/1/2013,B,112,47

];

Code:

Final:

load

Date,

Itemcode,

Branch,

if(Itemcode=peek(Itemcode) and Branch=Peek(Branch),rangesum(Qty,peek('runningQty') ),Qty) as runningQty

resident

Temp  order by Itemcode,Branch;


Above code didn't work.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think you need to sort your Final table LOAD by date ascending, too:

Final:

load distinct

Date,

Itemcode,

Branch,

if(Itemcode=peek(Itemcode) and Branch=Peek(Branch),rangesum(Qty,peek('runningQty') ),Qty) as runningQty

resident

Temp  order by Itemcode,Branch, Date;



edit:

Input:

LOAD * Inline [

Date,Itemcode,Branch,Qty

1/1/2013,A,112,7

1/1/2013,A,112,14

3/1/2013,A,113,10

4/1/2013,A,112,23

5/1/2013,B,112,23

5/1/2013,B,112,24

];

Final:

load distinct

Date,

Itemcode,

Branch,

if(Itemcode=peek(Itemcode) and Branch=Peek(Branch),rangesum(Qty,peek('runningQty') ),Qty) as runningQty

resident

Input  order by Itemcode,Branch,Date;

DROP TABLE Input;

Branch Itemcode Date runningQty
112A1/1/20137
112A1/1/201321
112A4/1/201344
112B5/1/201323
112B5/1/201347
113A3/1/201310

View solution in original post

1 Reply
swuehl
MVP
MVP

I think you need to sort your Final table LOAD by date ascending, too:

Final:

load distinct

Date,

Itemcode,

Branch,

if(Itemcode=peek(Itemcode) and Branch=Peek(Branch),rangesum(Qty,peek('runningQty') ),Qty) as runningQty

resident

Temp  order by Itemcode,Branch, Date;



edit:

Input:

LOAD * Inline [

Date,Itemcode,Branch,Qty

1/1/2013,A,112,7

1/1/2013,A,112,14

3/1/2013,A,113,10

4/1/2013,A,112,23

5/1/2013,B,112,23

5/1/2013,B,112,24

];

Final:

load distinct

Date,

Itemcode,

Branch,

if(Itemcode=peek(Itemcode) and Branch=Peek(Branch),rangesum(Qty,peek('runningQty') ),Qty) as runningQty

resident

Input  order by Itemcode,Branch,Date;

DROP TABLE Input;

Branch Itemcode Date runningQty
112A1/1/20137
112A1/1/201321
112A4/1/201344
112B5/1/201323
112B5/1/201347
113A3/1/201310