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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous789
Contributor
Contributor

Variable with parameter in load script

Hi everyone,

I am trying to use a variable with a parameter in my load script (when loading in a table).

This logic works in the front-end, but not sure about the back end.

Code:

LET vVariable = 1 + $1

Table:
Load 
      *,
      '$(vVariable(2))' as VarValue
From xxx
....

But the result is always empty (null)

I need this because, I have the same logic occuring multiple times (if statements) but for different fields. That's why I want to store the logic in a variable, and pass the field as a parameter. 
Already tried to do this with SUB routines, but it does not work either, so if anyone has some suggestions, always welcome!

Labels (4)
1 Solution

Accepted Solutions
rwunderlich
MVP
MVP

3 Replies
Sayed_Mannan
Creator II
Creator II

In QlikSense, the use of variables with parameters in the load script can be a bit tricky. The issue you're facing is likely due to the way Qlik handles variable expansion in the load script.

Here's a code that might help:


SET vVariable = '1 + $(#1)';

Table:
Load
*,
$(vVariable(2)) as VarValue
From xxx;

Here I used SET instead of LET to define the variable. The #1 is a placeholder that gets replaced by the parameter when the variable is invoked. The SET statement assigns the string literal to the variable, and the dollar sign expansion ($) still works

Remember, in QlikSense, SET creates a variable and assigns it a string literal, while LET assigns an existing variable to a value. So, using SET will still expand the $ sign, and the trick is to work around the $ sign when assigning the variable.

I hope this helps! 

rwunderlich
MVP
MVP

Anonymous789
Contributor
Contributor
Author

Changing the LET to SET indeed worked, thanks!