Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I have a list of categories and need to build in a script a loop to create a list of variables. Can you pls help?
Category:
1
2
4
5
7
8
9
variables to be built:
LET vCategoryNumberSummer = 'sum({<Category ={Category Number} >} Value) / Summer';
LET vCategoryNumberSummer = 'sum({<Category ={Category Number} >} Value) / Winter';
So I need to get as a result:
LET v1Summer = 'sum({<Category ={1} >} Value) / Summer';
LET v1Summer = 'sum({<Category ={1} >} Value) / Winter';
LET v2Summer = 'sum({<Category ={2} >} Value) / Summer';
LET v2Summer = 'sum({<Category ={2} >} Value) / Winter';
..
Thanks a lot for help.
Please try this instead:
LET $(vVarName) = 'sum({<Category ={"$(vCurrCategory)"} >} max(Value)) / Summer';
May be use the approach specified here:
Storing variables outside of QlikView - The Qlik Fix! The Qlik Fix!
Category:
LOAD * Inline [
Category
1
2
3
4
5
6
];
LET vCategories = NoOfRows('Category');
FOR i = 0 to $(vCategories) -1
vCurrCategory = peek('Category', $(i), 'Category');
LET vVarName = 'v' & '$(vCurrCategory)' & 'summer';
LET $(vVarName) = 'sum({<Category ={'$(vCurrCategory)'} >} Value) / Summer';
...
...
...
//you can have as many variables you want to create in each loop - meaning for each category
...
...
NEXT
I would use a slight different approach and create only one variable within the variablen-editor like:
vExp:
sum({<Category ={$1} >} Value) / pick($2, Summer, Winter)
and my expressions would look like:
$(vExp(1, 1)) // would be the same like: sum({<Category ={1} >} Value) / Summer
$(vExp(2, 2)) // would be the same like: sum({<Category ={2} >} Value) / Winter
- Marcus
Hi,
can you check what is the error in your script?
Thanks
Please try this instead:
LET $(vVarName) = 'sum({<Category ={"$(vCurrCategory)"} >} max(Value)) / Summer';