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: 
Mark_A
Contributor
Contributor

Load variables from a table

I would like to load some parameters into variables from a table "Parameters":
ParametersParameters

In the load script, I want to use the lookup function to store the value "Waarde" into the variable vKostIntern:

LET vKostIntern = Lookup('Waarde','Parameter','vKostIntern','Parameters');

I tried different things but the value of the variable remains empty.

Does anyone have a solution for this?

Labels (3)
1 Solution

Accepted Solutions
rubenmarin1

Hi, it should work, check again all the field and table tables, every is case-sensitive.

Also confirm that the table is already loaded in data model before the LET instruction.

Also note that you can create all variables from excel with a sfipt like:

 

Variables:
LOAD
  Parameter,
  Waarde
FROM ... excelFile;

FOR i = 0 to NoOfRows('Variables') - 1
    LET vParameter = Peek('Parameter',$(i),'Variables');
    LET $(vParameter) = Peek('Waarde',$(i),'Variables');
NEXT i

 

Maybe Waarde needs some number formatting with Num#() and/or Num() to correctly interpret the decimal separator.

View solution in original post

3 Replies
rubenmarin1

Hi, it should work, check again all the field and table tables, every is case-sensitive.

Also confirm that the table is already loaded in data model before the LET instruction.

Also note that you can create all variables from excel with a sfipt like:

 

Variables:
LOAD
  Parameter,
  Waarde
FROM ... excelFile;

FOR i = 0 to NoOfRows('Variables') - 1
    LET vParameter = Peek('Parameter',$(i),'Variables');
    LET $(vParameter) = Peek('Waarde',$(i),'Variables');
NEXT i

 

Maybe Waarde needs some number formatting with Num#() and/or Num() to correctly interpret the decimal separator.

MartW
Partner - Specialist
Partner - Specialist

@Mark_A , I think you should use a peek function instead.

I don't know how long your table is but this loop should work and create the variables for you

the Trace functions are there as a testing thing. you can remove those 🙂 

 

Parameters:
Load * inline [
Parameter, Waarde
vTest, 10
vTest2,100
];

let row = RowNo();
for Each vFields in FieldValueList('Parameter')

  Trace - $(vFields)-;
  let $(vFields) = peek('Waarde',$(row),'Parameters');
  let row = $(row) + 1;
  Trace - $(vFields)-;


next

 

 

 

Mark_A
Contributor
Contributor
Author

Hi Ruben, thanks for the reply.
This code is certainly helpful.

I found where I made an error:
I use $(vKostIntern) in my expressions, which turns out to be Null.
When I replace this with vKostIntern, without $(), everything works fine.

Previously, the value of the variable was hard-coded:
LET vKostIntern = 0.425;
In this case both $(vKostIntern) and vKostIntern return the value.

The use of $() still keeps confusing me sometimes.