Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

h_demarco
New 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.

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

Re: Nesting variables in script for set analysis

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
5 Replies

Re: Nesting variables in script for set analysis

qliksus
Valued Contributor

Re: Nesting variables in script for set analysis

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

MVP
MVP

Re: Nesting variables in script for set analysis

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
New Contributor III

Re: Nesting variables in script for set analysis

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
New Contributor III

Re: Nesting variables in script for set analysis

Yeahh... it worked!

Thank you so much.

Community Browser