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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

precalculated variables and the use of them.

Hi!

I have a beginner question,

Let's say I load 6 fields from a table :

LOAD

month,

sales_country,

amount_apples,

amount_oranges,

amount_other_fruit,

total_amount

FROM ...

Can I now define 3 variables which does straight calculations on those fields, so I declare those formulas once in my script, and I can use the variable name in my charts instead of doing the whole calculation per chart again?

so for example, can I add the following lines to my loadscript? :

vApples = amount_apples / total_amount;

vOranges = amount_oranges / total_amount;

vOthers = amount_other_fruit / total_amount;

Now I would like to make a chart, showing the avg % apples per country.

In the expressions, what do I have to do then?

is it :

sum($(vApples)) ?

Or does that not work?

muchos gracias!!

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Yes, you can use precalculate values and hold them in variables for reusing them in different chart objects.

Those precalculated values normally won't be sensitive to dimension values, though (e.g. ..per country).

You can also store the expression definition (i.e. the 'text' of an expression) in variables and reuse those in chart objects, but here they will be calculated in each chart object, being sensitive to dimension values.

Latter is more a kind of maintenance help then an improvement in calculation performance.

The main difference about the two is how you define them (using LET or SET in script, using or not using the equal sign in variable overview).

Please have also a look at this blog:

http://www.qlikfix.com/2011/06/08/not-all-variables-are-created-equal/

View solution in original post

2 Replies
jagan
Partner - Champion III
Partner - Champion III

Hi,

If you calculate values in variables, and these variables are used in the charts then it would not split the values by dimension, it shows the same values for all the values in the dimension.

Instead of that, create a variable with formula without using the Set.

Check the attachment for reference.

Regards,

Jagan.

swuehl
MVP
MVP

Yes, you can use precalculate values and hold them in variables for reusing them in different chart objects.

Those precalculated values normally won't be sensitive to dimension values, though (e.g. ..per country).

You can also store the expression definition (i.e. the 'text' of an expression) in variables and reuse those in chart objects, but here they will be calculated in each chart object, being sensitive to dimension values.

Latter is more a kind of maintenance help then an improvement in calculation performance.

The main difference about the two is how you define them (using LET or SET in script, using or not using the equal sign in variable overview).

Please have also a look at this blog:

http://www.qlikfix.com/2011/06/08/not-all-variables-are-created-equal/