Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

lionel_b
New Contributor

Variable not working in some objects

Hello everyone,
 
I created a variable with a set analysis in order to calculate a measure, but it does not work in all the objects of my app. For example, the variable works with a KPI object, but does not work with a bar chart : it gives me the same values for all the dimensions of the bar chart. However, when I use directly the set analysis and not the variable, all the objects including the bar chart work perfectly.
Loading the variable directly from the load editor does not change anything to this problem either.
 
Here is an example :
With set analysis:                                                                                   With variable:
                                           
 
Do you have any idea concerning the origin of the problem?
Many thanks in advance.
1 Solution

Accepted Solutions

Re: Variable not working in some objects

If you creates a variable with the name x and the content of: sum(AnyValue) without using a leading equal-sign you could use $(x) as expression within the chart as if you have typed sum(AnyValue) there.

- Marcus

8 Replies

Re: Variable not working in some objects

I assume that your variable begins with a equal-sign "=" which meant that the expression will be calculated and the result will be stored within the variable. See for this: The Little Equals Sign.

- Marcus

shraddha_g
Honored Contributor III

Re: Variable not working in some objects

how you have defined variable?

lionel_b
New Contributor

Re: Variable not working in some objects

Hi Marcus,

Thank you for your reply. My variable begins with the sign = so it calculates the expression and it is not considered as a text (as I understood it from the link you gave me).

It looks like the variable calculates one value and applies it to all the dimensions, even if the variable is created with Let statement.

lionel_b
New Contributor

Re: Variable not working in some objects

Hi Shradda, my variable is defined with a Let in a scipt, and looks like this:

=Count( {$< [Field_1]={1},[Field_2] ={1}, [Field_3]={1}> }distinct Field_4)

Re: Variable not working in some objects

Yes, that's right. By a variable-declaration beginning with the equal sign or within the script per LET will be at first evaluated and only the result of them is stored within the variable and of course each call of the variable has then the same return-value.

- Marcus

lionel_b
New Contributor

Re: Variable not working in some objects

Ok, I understand it right now. But does it mean that it is not possible to use variables in bar charts (or other objects with several dimensions), or is there a way to make it work?

Re: Variable not working in some objects

If you creates a variable with the name x and the content of: sum(AnyValue) without using a leading equal-sign you could use $(x) as expression within the chart as if you have typed sum(AnyValue) there.

- Marcus

lionel_b
New Contributor

Re: Variable not working in some objects

Thank you Marcus, it works perfectly :-)