Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Create a variable for code based on selection

Hello,

I am hoping to create a variable that I can use multiple times in a code.  It should be based on a selection of a list box.

For example, I created a list box called Age_Group.  When the user selects '30-39' in the Age_Group box, I want string '30-39' to be put in the equations below in the place of the variable vAge.  Below is the code that I tried:

set vAge = [Age_Group];

Expression:
load * inline [
Expression, Exp
'Medical Incurred', sum({<Age_Group= {$(vAge)}>} T_ITD_INCRD_MED_AMT)/sum(total <Accident_Year> T_ITD_INCRD_MED_AMT)
'Indemnity Incurred', sum(<Age_Group> T_ITD_INCRD_INDM_AMT)/sum(total <Accident_Year> T_ITD_INCRD_INDM_AMT)
'Indemnity Paid', sum({<Age_Group= {$(vAge)}>} T_ITD_PD_INDM_AMT)/sum(total <Accident_Year> T_ITD_PD_INDM_AMT)
]
;


Side note: I am already taking 2 different list boxes into account when creating these equations, hence why I already used the load inline statements.  I am open to any other suggestions that involve taking several fields.  It gets a bit complicated when looking at percentages of a whole set number.  I'm trying my best at learning set analysis


Thanks for any help you can provide!

1 Solution

Accepted Solutions
tresesco
MVP
MVP

This way you can't pass your selection to script (during load). Instead of loading the expressions, define variables in the front-end.

View solution in original post

4 Replies
tresesco
MVP
MVP

This way you can't pass your selection to script (during load). Instead of loading the expressions, define variables in the front-end.

Not applicable
Author

Thank you for your response!  Can you please clarify what you mean?  I tried moving the set vAge = [Age_Group];
to the very beginning of the script, but this didn't seem to work.

tresesco
MVP
MVP

Open your application-> press Ctrl+Alt+V , you would get the variable overview window where you can define variables in the front-end. The variavles defined in here, are responsive to selection.

Not applicable
Author

Thank you, this worked!

It didn't end up working in the inline statement like I had above, so instead I used conditional hide/ unhide under expressions.  For anyone's reference, I used this equation:

=sum({$<Age_Group= {'$(vAge)'}>} T_ITD_INCRD_INDM_AMT)/sum(T_ITD_INCRD_INDM_AMT)