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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load script: Define variable and assign an expression with set analysis

Hi,

In the load script, I want to define a variable and assign an expression to it. However, I am getting an error

Let  ClassificationDimensionName  = only({<%ClassificationDimensionId = {$1} >} %ClassificationDimension) ;

Can someone please tell me how to define such expressions in load script

Shah

7 Replies
nickking
Contributor III
Contributor III

Hi Shah,

I'm afraid you can't use set analysis in the load script. However you should be able to create a variable in the Variable Overview (Ctrl+Alt+V) that uses set analysis to define your ClassificationDimensionName.

If that doesn't work it might help if you can post a qvw file example for us to refer to.

Hope this helps

Nick

Peter_Cammaert
Partner - Champion III
Partner - Champion III

LET will try to evaluate everything right from the equal sign. No set analysis in scripts, sorry.

Use SET statement instead LET.

Not applicable
Author

Well actually these variables are defined in the variable overview. However, I am using a source control and need to define and declare all the variables in the load script so that If someone gets the version from source control, they don't lose the variables definitions and values

Is there any other way I can achieve this? The only option I can think of is to declare them all in the load script

Shah

Peter_Cammaert
Partner - Champion III
Partner - Champion III

If you are using VC, there is no other option as QV won't store the actual variable values in an xml when saving to your version control system.

To regain some flexibility, you could store the variable values in an external source file, or store them in an Excel file. The first solution offers one more trick: you'll need the external source file only after every extract from VCS. All subsequent reloads will never complain about a missing source file (that's what $(Include) is good at)  and will keep the variables untouched.

Peter

karolina_
Creator II
Creator II

Hi Shah,

I have it like this:

Load Script:

set vVariable = count({$<[Tier]={$1,$2}, [Stream]={$3,$4}, [Flag]={1}>} DISTINCT [ID]);

Call of Variable:

$(vVariable('I','II','SI','SII'))

Not applicable
Author

Hi,

In the loadscript, I have the below variable definition

Set f_CreateSheetVisibilityVariable = 'v_' & $1 & PURGECHAR($(=$1 & 'FrontMenu' & $2), ' -+*/^(){}%&#"') & 'Visible';

However, when I check the definition of CreateSheetVisibilityVariable in the variable overview, I can only see

'v_' & $1 & PURGECHAR(, ' -+*/^(){}%&#"') & 'Visible'

The $(=$1 & 'FrontMenu' & $2) seems to have disappeared. Can someone please tell me how to set the variable in the load script so that this part does not get evaluated/disappear during the loadscript reload

Shah

Peter_Cammaert
Partner - Champion III
Partner - Champion III

That's because $-substitution is executed just before the SET statement is parsed. The parameters however stay put.

A possible solution could be to use another character for delayed $-sign substitutions, and replace this in a subsequent LET statement. The script engine won't notice because at the time the engine parses statements, there isn't anything visible that looks like $(...). For example:

Set f_CreateSheetVisibilityVariable = 'v_' & $1 & PURGECHAR(#(=$1 & 'FrontMenu' & $2), ' -+*/^(){}%&#"') & 'Visible';

Let f_CreateSheetVisibilityVariable = replace(f_CreateSheetVisibilityVariable, '#', '$');