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: 
Anonymous
Not applicable

Variable Evaluation on File Load

I know I've seen this addressed before but I can't find the discussion(s).

When loading variables from a file during script load, how do you keep embedded variables from being evaluated?

For example (off the top of my head, so maybe not a great example):

<Variables.txt>

SET vEndDate = "=Max(Order_Date)";

SET vEndMonth = "=Month($(vEndDate))";

After the variable file is read into the script during load, vEndMonth is doesn't give me 'Sep', for example, it just contains the literal string =Month($(vEndDate).

9 Replies
Anonymous
Not applicable
Author

you need to write variable "statement" in single quote, instead of double:

SET vEndDate = 'Max(Order_Date)';

vgutkovsky
Master II
Master II

You're right, you've seen it before Here's a link to one such discussion with several different solutions: http://community.qlik.com/thread/133348

Vlad

bimartingo
Contributor III
Contributor III

Hi Brian,

I know, variables evaluation is a very complicated matter, you can never be sure exactly the way they gonna behave, but first of all you have to understand the difference between the SET and the LET instruction.

if you want a variable to evaluate to some value, i. e., using a formula, you'll have to use the LET instruction, not SET.

In your example it would be (with single quotation also corrected)

SET vEndDate = '=Max(Order_Date)';

LET vEndMonth = '=Month($(vEndDate))';

I think it will evaluate to the formula =Month(=Max(Order_Date))

whatever it's meaning is, but I'm not sure.

I'm afraid this is only the beginning of your challenge

Good luck

Anonymous
Not applicable
Author

Someone at the Qlik conference here in Orlando said that if you are using $ expansion in the variable definition, you do not want to proceed the expression with a = sign since this causes the Ajax client to recalculate the expression on every click, leading to possible performance degradation. Has anyone else heard this?

Not applicable
Author

Do you mean an equals in the variable itself? If so then yes, the equals will cause it to be a global variable, calculated on each selection. Without the equals you can dollar expand and calculate specifically when you want to

Anonymous
Not applicable
Author

Thanks for the reply Joe. I'm not sure I follow - can you post an example both ways?

Not applicable
Author

No problem,

Set vVariable1 = '=Only(Myfieldhere)'

The = results in a global variable

Set vVariable2= 'Only(Myfieldhere)'

without the = does not

Anonymous
Not applicable
Author

Excellent. What if the variable definition contains a dollar expansion reference to another variable?

Not applicable
Author

That's fine you are able to do that yes, all the equals is doing in the variable is defining when it is evaluated.

In my example above if you create two text boxes to call each.

Txtbx1:

=vVariable1

would return 'bob' for instance if that was the only selection from Myfieldhere

Txtbx2:

=vVariable2

would return Only(Myfieldhere), as it hasn't been evaluated yet. You would need to do =$(vVariable2) to return 'bob'

hope that makes sense

Joe