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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

fill variable from table

hi,

I have several variables in which a user can provide a number from 0 till 50, the variables are: A1, B1, C1 .
In a chart this variable is used to perform a calculation.
In the data i also have a table which has values voor A1, B1, C1, i would like to use those values as the default value for my variables but i don't know how to..

I was thinkin' something like this but it doesn't work...





for

Each record in OPNAME_AFDELING
If(OPNMUTAFDELING='A1', LET A1 = OPNMUTAFDELINGBeddenaantal);
next record



for Each record in OPNAME_AFDELING
If(OPNMUTAFDELING='B1', LET B1 = OPNMUTAFDELINGBeddenaantal);
next record

help would be appriated!

thanx

david





1 Solution

Accepted Solutions
Not applicable
Author

Just define another variable and peek the value into it, then use its content to create the variable name:

FOR i = 0 to NoOfRows('resident table')-1
LET vFieldValue = peek ('otherfieldname, i, 'resident table');
LET vVariable$(vFieldValue) = peek('fieldname', i, 'resident table');
NEXT ;

Of course the value in vFieldValue cannot contain a space or other reserved character as this is not allowed in a variable name (you could strip out the spaces using PurgeChar or Replace string functions though)

Regards,

Gordon

View solution in original post

8 Replies
Not applicable
Author

Not sure I have understood but does this give you any ideas?

FOR i = 0 to NoOfRows('resident table')-1
LET vVariable$(i) = peek('fieldname', i, 'resident table');
NEXT ;

This will go through each row in a resident table and create a variable identified by the row number with the value of a field within that row.

Regards

Gordon

Not applicable
Author

Hi Gordon,

thanx for your reply, i copied your script in my script:
FOR i = 0 to NoOfRows('OPNAME_AFDELING')-1
LET vVariable$(i) = peek('OPNMUTAFDELINGBeddenaantal)', i, 'OPNAME_AFDELING');
NEXT;

This made about 40 variables with a value from the table, it is allmost what i want, in my case the variables allready excist.
I would like to store the values in variables with names that are the same as another field in the table, is it possible to give the variable a name from another field from the table?

regards,

david

Not applicable
Author

Hi David, hi Gordon,

what do you think about input fields ? You can use wildards for the declaring and load them with the defaults you want:


Inputfield Type;
Tbl:
Load * inline
[Val, Type
10, A
100, A
1000, A
20, B
50, C
500, C
220, D
100, D
];


RR

Not applicable
Author

hi kurokarl,

in fact i have a tab where i have inputfields, the script above is to get the default values for the inputfields from a table..

does this help?

regards,

david

Not applicable
Author

Just define another variable and peek the value into it, then use its content to create the variable name:

FOR i = 0 to NoOfRows('resident table')-1
LET vFieldValue = peek ('otherfieldname, i, 'resident table');
LET vVariable$(vFieldValue) = peek('fieldname', i, 'resident table');
NEXT ;

Of course the value in vFieldValue cannot contain a space or other reserved character as this is not allowed in a variable name (you could strip out the spaces using PurgeChar or Replace string functions though)

Regards,

Gordon

Not applicable
Author

hi Gordon,

this works! thanx.

Is it also possible to exclude some rows/variables?
Something like:

where OPNMUTAFDELINGLocatie = 'S'

regards,

david

Not applicable
Author

sure - you can make any lines of code conditional by wrapping them in IF..THEN..ELSE

IF A=0 THEN

(do something)

END IF

Not applicable
Author

thanx for all help, the result is great..

regards,

david