Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

set and let

Per the documentation, I would like to point out the difference between how set and let actually behave and what the document seems to suggest.

If in the script I have:

SET A = 'hello';

SET B = $(A);

Then I should expect in the variable overview just that because as specified in the document, the SET command does not evaluate the right-hand-side (RHS).

Rather, the variable overview shows both the variable A and B to have the string hello, which implies that the RHS are evaluted before being passed to the variable.

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

I realised after posting the above that you may be wanting to set a variable to an unexpanded $ so that this can be expanded when it is evaluated later in an expression.

To do this I have done one of the following:

Set B = #(A);

Let B = Replace(B, '#", '$');

or

Let B = '$' & '(A)';

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

9 Replies
jvitantonio
Luminary Alumni
Luminary Alumni

If you use $( ) it will return the variable content. In this case 'hello'. It's like doing SET B = 'hello', If you want to store literally $(A) then write SET B = '$(A)';

Not applicable
Author

Thanks for the reply. But that does not seem to do it. Here is an example:

SET A = 'hello';

SET B = '$(A)';

Again both A and B contain hello.

The documented behavior is that SET does not evaluate the RHS. So a dollar sign $ should not be evaluated as well.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

The $ expansion is performed before the SET expression executes, and SET does not evaluate the expression passed to it. You will see this in the debugger if you step through the code.

Consider the following:

Set A = 1+2;

Set B = $(A);

Let C = $(A);

B will contain '1+2' (not evaluated) and C will contain '3' (evaluated)

Hope that helps clear things

Regards

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

I realised after posting the above that you may be wanting to set a variable to an unexpanded $ so that this can be expanded when it is evaluated later in an expression.

To do this I have done one of the following:

Set B = #(A);

Let B = Replace(B, '#", '$');

or

Let B = '$' & '(A)';

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thank you, it does clear things. I think I have to keep in mind the difference between Expansion as in "all dollar-sign expression will get expanded regardless whether it is a SET or LET", and Evaluation as in "LET evaluates the RHS, SET does not".

What I would like to do is to define a formula in the script editor. Currently, I use the workaround of having ~ to replace any occurrence of $. Then use the REPLACE to replace the ~ to $.

SET B = ~(A);

LET B = replace('$(B)','~','$');

Any better way?

Your example is on numerical example. I think I still have problems with the SET handling a string. Here is another example where I think shows the inconsistency in the SET command.

SET C = 'hello';

SET D = customer_id = 'hello';

The variable overview shows C to contain hello, whereas D to contain customer_id = 'hello'

If SET were consistent, C would contain 'hello', with the single quotes preserved. If you can enlighten what happens in the code for this case, that will be helpful as well. Thank you.

jonathandienst
Partner - Champion III
Partner - Champion III

yohan

You can simplify your script slightly:

SET B = ~(A);

LET B = replace(B,'~','$');

On the quotes, I do agree with you. It seems that if the quotes enclose the entire string, they are discarded, but if they are inside the string, then they are retained.

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Jonathan,

Thank you for that tip.

While there is a workaround, I think that it would be nice to make the SET and LET behavior more consistent. Do you know how we can submit a software change request to the Qlikview developers?

jvitantonio
Luminary Alumni
Luminary Alumni

Go up in, and clik on "Ideas" and then in the menu on the right you have an option to "Create Idea"

Not applicable
Author

Thank you.