Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

could I call a Sub since Expressions

Hi experts,

I han a sub in the Script área, this sub can I call in a Expression?

Best regards.

1 Solution

Accepted Solutions
jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Hi,

you can create variables with parameters, so you can have something like "user defined functions" within charts.

An easy example would be something like this:

Let's say your formula is Sum({$<Product={'$1'}>} Sales). In this case the '$1' part, will be calculated until there is some interaction with an external event (like a user selecting one or more products from a listbox). It is important to note that your "dynamic" variable cannot be precalculated, otherwise it won't work correctly. This means that when you create your variable you should not include a = at the beginning of your expression.

Then when calling this variable you need to use the following syntax: $(VariableName(Parameter1, parameter2, parameterN)). Just like in a sub you can define 1 or any number of parameters.

This QlikView Feature allows you to reuse a single variable for many different scenarios and to make your variables more dynamic,

regards

View solution in original post

11 Replies
Anonymous
Not applicable
Author

no, you can't execute backend function from frontend (macro excepted)

Not applicable
Author

well in that case,

could  I set a variable for axample selecting a value from list box?

best regards

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Hi,

you can create variables with parameters, so you can have something like "user defined functions" within charts.

An easy example would be something like this:

Let's say your formula is Sum({$<Product={'$1'}>} Sales). In this case the '$1' part, will be calculated until there is some interaction with an external event (like a user selecting one or more products from a listbox). It is important to note that your "dynamic" variable cannot be precalculated, otherwise it won't work correctly. This means that when you create your variable you should not include a = at the beginning of your expression.

Then when calling this variable you need to use the following syntax: $(VariableName(Parameter1, parameter2, parameterN)). Just like in a sub you can define 1 or any number of parameters.

This QlikView Feature allows you to reuse a single variable for many different scenarios and to make your variables more dynamic,

regards

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

for your example if you want the user to calculate something depending on a selection, regarding my previous post, the variable call would be like this:

$(VariableName( $(=Concat(distinct Product, chr(44) ))

I used this concat function in order to allow users to calculate for example the sum of sales of 1 or any product that is selected in a listbox.

you can also store the $(=Concat(distinct Product, chr(44)) in another variable so it can be easier for end-users to reuse expressions across different variables,

regards

Not applicable
Author

Thanks a lot Jaime.

Not applicable
Author

Jaime,

I need set that you sed since the setings ->Variables Panel?

best regards.

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

Yes, the easiest way of creating variables is going to settings > variable overview (Panel de variables)

regards

Not applicable
Author

ok,

but a mean the sentence of your example '$(Variablename($=Concat(Distinct  Product,chr(44)))'

I can set in the setings or directly in a Expression?

best regards.

jaimeaguilar
Partner - Specialist II
Partner - Specialist II

For this example the expression has to be:

sum({$<Product={'$1'}>}Sales)

So let's say this expression is inside a variable called v1

then when you call it in a chart you have to use this syntax:

$(v1( $(=Concat(Distinct  Product,chr(44))) )) The text in bold is the parameter of your variable.

the $(=Concat(Distinct  Product,chr(44))) can be anything. When the variable is calculated the '$1' in your original expression will be substituted with whatever you put inside the parameter of the variable.