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

Sub-Running Sum By ID

Hello Qlikers,

I want to Calculate the Sum Field By ID as per the below example, How that you can help with this. Thank you!

IDCountSum
116
105
115
104
114
103
113
112
111
214
203
213
212
211

 

1 Solution

Accepted Solutions
Vegar
MVP
MVP

You will need to do this in the script. 

You can do something like this

Load

  [ID] ,

  [Count] ,

  if(peek('ID') =[ID] , Peek('Sum') +[Count], [Count]) as [Sum]

From Source

Order by [ID] //makes sure you process one ID at the time

;

View solution in original post

5 Replies
Vegar
MVP
MVP

You will need to do this in the script. 

You can do something like this

Load

  [ID] ,

  [Count] ,

  if(peek('ID') =[ID] , Peek('Sum') +[Count], [Count]) as [Sum]

From Source

Order by [ID] //makes sure you process one ID at the time

;

mario-sarkis
Creator II
Creator II
Author

Hello Thank you for the reply,

I am trying the below expression in the script but it is not giving the required output of calculated the sum. The output sum is calculating the followed Rows as the screenshot below: Hope you can help with this. Thanks again

IDCountSum
115
104
114
103
113
112
111
214
203
213
212
211
Vegar
MVP
MVP

It looks quite similar to me. You have less rows in your second example than in your first.

Please explain the difference? 

Vegar
MVP
MVP

I've created a qvw where I calculate the same output as your expected output.

Take look at the image below.

Vegar_0-1594207676889.png

 

 

Kushal_Chawda

You may need to create additional step to sort the data

Data:
LOAD 
    ID,
    "Count"
FROM [lib://Qlik]
(html, utf8, embedded labels, table is @1);

New:
NoConcatenate 
Load *,
     if(Peek(ID)<>ID,1,rangesum(Peek(Rank),1)) as Rank
Resident Data
Order by ID; // here you cn sort the data way you want to present.

Drop Table Data;

Final:
NoConcatenate
Load *,
    if(Peek(ID)<>ID,Count,rangesum(Peek(Sum),Count)) as Sum
 Resident New
Order by ID,Rank desc;

Drop Table New;