Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
entsh
Contributor II
Contributor II

SUM WITH PREVIOUS ROW FOR EACH NAME

hi

please see the table 1

ROWNAMENUMBER1-SUM (SUM WITH PREVIOUS ROW FOR EACH NAME)FROM SMALLEST ROW TO LARGEST ROW NUMBER 
1A500=500 
4A450450+500=950 
8A550950+550=1500 
10A10001500+1000=2500 
15A5002500+500=3000 
3B400=400 
5B600=400+600=1000 
42B7001000+700=1700 

 

RESULT

NAMERESULT (TOTAL SUM)
A3000
B1700

 

I WANT THE FORMULA FOR 1-SUM COLUMN AND 2-RESULT TABLE

 

THX

1 Solution

Accepted Solutions
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    ROW, NAME, NUMBER
    1, A, 500
    4, A, 450
    8, A, 550
    10, A, 1000
    15, A, 500
    3, B, 400
    5, B, 600
    42, B, 700
];

tab2:
NoConcatenate
LOAD *, If(Previous(NAME)=NAME, RangeSum(NUMBER,Peek('NUMBER_ACC')),NUMBER) As [1-SUM]
Resident tab1
Order By NAME, ROW;

Left Join(tab2)
LOAD NAME, Sum([1-SUM]) As RESULT
Resident tab2
Group By NAME;

Drop Table tab1;

View solution in original post

3 Replies
mato32188
Specialist
Specialist

Hi @entsh ,

if you have not sorted your table yet, please do the following in script:

tmp:

Load 

ROW,

NAME,

NUMBER

from xxx;

noconcatenate

tmp1:

load * resident tmp order by NAME; drop table tmp;

tmp2:

load

ROW,

NAME,

NUMBER,

if(previous(NAME)=NAME, rangesum(NUMBER,peek('NUMBER_ACC')),NUMBER) as NUMBER_ACC

Resident tmp1;

drop table tmp1;

Then you can simply sum the NUMBER_ACC in any object you want.

BR

m

 

 

ECG line chart is the most important visualization in your life.
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    ROW, NAME, NUMBER
    1, A, 500
    4, A, 450
    8, A, 550
    10, A, 1000
    15, A, 500
    3, B, 400
    5, B, 600
    42, B, 700
];

tab2:
NoConcatenate
LOAD *, If(Previous(NAME)=NAME, RangeSum(NUMBER,Peek('NUMBER_ACC')),NUMBER) As [1-SUM]
Resident tab1
Order By NAME, ROW;

Left Join(tab2)
LOAD NAME, Sum([1-SUM]) As RESULT
Resident tab2
Group By NAME;

Drop Table tab1;
Saravanan_Desingh

Output:

commQV68.PNG