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: 
Not applicable

dynamic list of variables

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.

1 Solution

Accepted Solutions
boorgura
Specialist
Specialist

Please try this instead:

LET $(vVarName) = 'sum({<Category ={"$(vCurrCategory)"} >} max(Value)) / Summer';

View solution in original post

5 Replies
sunny_talwar

boorgura
Specialist
Specialist

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

marcus_sommer

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

Not applicable
Author

Hi,

can you check what is the error in your script?

Thanks

boorgura
Specialist
Specialist

Please try this instead:

LET $(vVarName) = 'sum({<Category ={"$(vCurrCategory)"} >} max(Value)) / Summer';