Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
MCA
Contributor
Contributor

Counter or variable manipulation within load script?

Is it possible to update / change the value of a variable within the load script? 

Test:
LOAD * Inline [
ID, amount
1, 50
1, 100
99, 70
5, 25
5, 20
5, 10
5, 21
5, 69
]; 

With this data I would like to be able to sort it by ID and then amount.  I'd like the load script to analyze the ID; if it repeats it should add 1, then 2, and so on.  I've tried adding the data to a temporary table and using Peek() and Previous() along with a variable and counter but have had no luck.  With the data provided the goal would be to the following:

ID, amount, New Value

1, 50, 11

1, 100, 12

5, 10, 51

5, 20, 52

5, 21, 53

5, 25, 54

5, 69, 55

99, 70, 991

 

 

 

 

 

 

Labels (3)
1 Solution

Accepted Solutions
lironbaram
Partner - Master III
Partner - Master III

hi

this will do the trick 


Test:
LOAD * Inline [
ID, amount
1, 50
1, 100
99, 70
5, 25
5, 20
5, 10
5, 21
5, 69
];

table:
load *,num(ID&counter) as newValue;
load * , if(Previous(ID)=ID,RangeSum(peek('counter'),1),1) as counter
Resident Test
order by ID,amount;


drop Table Test;

View solution in original post

2 Replies
lironbaram
Partner - Master III
Partner - Master III

hi

this will do the trick 


Test:
LOAD * Inline [
ID, amount
1, 50
1, 100
99, 70
5, 25
5, 20
5, 10
5, 21
5, 69
];

table:
load *,num(ID&counter) as newValue;
load * , if(Previous(ID)=ID,RangeSum(peek('counter'),1),1) as counter
Resident Test
order by ID,amount;


drop Table Test;

MCA
Contributor
Contributor
Author

That took care of it. Thank you for the quick solution!