Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Jhon34
Contributor
Contributor

Sum values on scriptId

Hi All,

I have 3 scriptID in my dataset as 1,2 and 3

I am doing sum row by row per scriptID using range sum.I have a requirement as below

You can see below in my table there are ScriptID's with their values.So i need sum for ScriptID is 1 as (5+5+5+5)=20, for ScriptID is 2 as (10+10+10+10)=40 and for ScriptID is 3 as (20+20+20+20)=80(Please refer sccreenshot below)

But i am getting all amount suming up without looking scriptID.

Can anyone have idea how to do sum like this through scripts.

Jhon34_0-1626531319434.png

 

Used below scripts in my application:

Test:
load *,
RangeSum(Peek('NewValue'),Value) as NewValue;

LOAD
ScriptID,
Value,
"Date"
FROM [lib://AttachedFiles/SampleData.xlsx]
(ooxml, embedded labels, table is Sheet2);

Please find attached sample data file.

Thanks 

1 Reply
chrismarlow
Specialist II
Specialist II

Hi,

Suggest you could modify the IF statement here;

Solved: Script: cumulative sum + group by - Qlik Community - 1810410

To something like;

If(RowNo()=1,
		Value,
		If(ScriptID=Peek(ScriptID),
			Peek([NewValue])+Value,
			Value
			)
		)  AS [NewValue]

Making sure your data is sorted by ScriptID then Date as it goes in to the preceeding load. 

Cheers,

Chris.