Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
That should be:
SET vVariable = 1 + $1;
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
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!
That should be:
SET vVariable = 1 + $1;
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
Changing the LET to SET indeed worked, thanks!