Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
marcel_olmo
Partner Ambassador
Partner Ambassador

Load variables dinamically directly in the script

Hey guys, I'm trying to configure some "configuration data" in an excel sheet, and then load them into a qlikview file and turn them into qlikview variables. But I have no Idea how to do it.

What I want is the following :

load * inline [

variable, value

vMin , 1

vMedium , 2

vMax, 3

];

//turn them into variables with the "let" or "set" stuff, but I have no idea about create a variable "vMin" with the value 1, and so on.

Could somebody help me with this stuff? Or the only way to do it is with a macro?

Many thanks in advance!

1 Solution

Accepted Solutions
pover
Luminary Alumni
Luminary Alumni

Try something like the following script:

Expresiones:
LOAD Variable,
Expresion
FROM
Expresiones.xlsx
(ooxml, embedded labels, table is Sheet1);

Let vNroRegistros = NoOfRows('Expresiones');

For vI = 0 to (vNroRegistros - 1)

Let vNombre_Variable = Peek('Variable',vI,'Expresiones');

Let [$(vNombre_Variable)] = Peek('Expresion',vI,'Expresiones');

Next

Regards.

View solution in original post

6 Replies
Not applicable

I'm not sure you're going to be able to dynamically define the variable names.

In order to store loaded data in a variable, you would use something like:

Let vMin = Peek('value', 1)
I tried a couple of combinations of dollar sign expansions on the variable name, but I couldn't get anything to work.
A workaround may be to use a text file and the Include statement. In the text file, use:
Set vMin = 1;
Set vMedium = 2;
...

And then in your load, use:
$(Include=C:\Path\For\Text\File.txt);
That will allow you to have all of the variable definitions in one place.

pover
Luminary Alumni
Luminary Alumni

In the script, you could put Let vMin = peek('variable',0); and then Let vMedium = peek('variable',1), etc.

Or you don't have to use variables. In the application you can use the expression

only({$<variable={'vMin'}>} value)

Regards.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Thank you both for answer me so quickly.

What I'm trying to do is to load the data with no idea of the names of the variables, it was only a figured example.

Could I put the name of the variable dynamically without knowing the name of the variable?

Many thanks anyway.

colinh
Partner - Creator II
Partner - Creator II

Hi Marcel

This might do what you want:



LOAD * INLINE [
Variable, Value
vMin, 1
vMed, 2
vMax, 3
];


let vVariable1 = fieldvalue('Variable', 1);
let vValue1 = fieldvalue('Value', 1);
let $(vVariable1) = $(vValue1);

let vVariable2 = fieldvalue('Variable', 2);
let vValue2 = fieldvalue('Value', 2);
let $(vVariable2) = $(vValue2);


let vVariable3 = fieldvalue('Variable', 3);
let vValue3 = fieldvalue('Value', 3);
let $(vVariable3) = $(vValue3);




pover
Luminary Alumni
Luminary Alumni

Try something like the following script:

Expresiones:
LOAD Variable,
Expresion
FROM
Expresiones.xlsx
(ooxml, embedded labels, table is Sheet1);

Let vNroRegistros = NoOfRows('Expresiones');

For vI = 0 to (vNroRegistros - 1)

Let vNombre_Variable = Peek('Variable',vI,'Expresiones');

Let [$(vNombre_Variable)] = Peek('Expresion',vI,'Expresiones');

Next

Regards.

marcel_olmo
Partner Ambassador
Partner Ambassador
Author

Many thanks Karl, that was exactly what I was looking for. Loading dynamically variables and their values into the script.

See you around!!