Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
h_demarco
Contributor III
Contributor III

Nesting variables in script for set analysis

Folks,

I have a variable in my script that is

Set var_IAP= =Sum({<Tipo_ap={Produção}, ETAPA-={50,21,100}>} QUANTIDADE)

'Etapa' exclusion is very common and I need to change it frequently (include another number like 200), so I created a new variable:

Set var_etapa_excluir= , ETAPA-={50,21,100};

And now I am trying to nest both using:

=Sum({<Tipo_ap={Produção} var_etapa_excluir >} QUANTIDADE)

Note that in many cases I need to exclude 'Etapa', but not in all cases. So my concern is to use as a variable, to avoid editing all the script that has more than 20 other variables.

In chart I just use var_IAP.

What is the correct way to nest variables in script? What am I doing wrong?

Thanks and best regards.

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

This should work:

Set var_etapa_excluir= , ETAPA-={50,21,100}; 

Set var_IAP = =Sum({<Tipo_ap={Produção} #(var_etapa_excluir) >} QUANTIDADE);

Let var_IAP = Replace(var_IAP, '#', '$');

The reason for two steps for var_IAP is to defer the $ expansion of var_etapa_excluir until the expression is evaluated in the front end. "Set" will expand the variable so it will no longer be dynamic.

We substitute # for $ to prevent the expansion and put it back with the replace step. The replace does not trigger the expansion.

You may get syntax warnings because the syntax check does not know what you intend to do with the variables.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

5 Replies
sunny_talwar

qliksus
Specialist II
Specialist II

Not  sure if I have understood you correctly ? If you say you have to exclude ETAPA for some cases so why cant you put that case outside the SET like

If case1 , sum({<ETAPA-={0,1,200}> } amount)  else sum(amount)  and do you really need to create 2 variables as you can edit the filters in the ETAPA even if you use 1 variable

jonathandienst
Partner - Champion III
Partner - Champion III

This should work:

Set var_etapa_excluir= , ETAPA-={50,21,100}; 

Set var_IAP = =Sum({<Tipo_ap={Produção} #(var_etapa_excluir) >} QUANTIDADE);

Let var_IAP = Replace(var_IAP, '#', '$');

The reason for two steps for var_IAP is to defer the $ expansion of var_etapa_excluir until the expression is evaluated in the front end. "Set" will expand the variable so it will no longer be dynamic.

We substitute # for $ to prevent the expansion and put it back with the replace step. The replace does not trigger the expansion.

You may get syntax warnings because the syntax check does not know what you intend to do with the variables.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
h_demarco
Contributor III
Contributor III
Author

I think my explanion was not clear, but below explanation may help:

I have 100 variables and 80 of them contain <ETAPA-={0,1,200}>. If I want to include one ETAPA number into array like <ETAPA-={0,1,200,205}>, will I need to change 80 lines of code?

h_demarco
Contributor III
Contributor III
Author

Yeahh... it worked!

Thank you so much.