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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

set a variable within the load statement

Dear QV community

unfortunately I can not find suitable solution for my problem in the forum.
How can I set variables in the load block ? Thank you!


Here a pseudocode of my intension !

<qlikview script>

MyTable:

LOAD models,
if( product= 'white', productcode = '7231', productcode='7000' ) as productColor,
price,
quantity

FROM
items.csv (txt, codepage is 1252, embedded labels, delimiter is ';', msq);

</qlikview script>

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

The short answer is that you cannot set variable values within a LOAD statement. You can, however, interrogate the loaded data after loading and set a variable based on the outcome. For example:

MyTable:

LOAD models,
productColor,
price,
quantity

FROM
items.csv (txt, codepage is 1252, embedded labels, delimiter is ';', msq);

tmp:
LOAD Count(productColor) As WhiteCount
Resident MyTable;

Let productcode = (If(Peek('WhiteCount') > 0, '7231', ''));
...

Drop Table tmp;


Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

1 Reply
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

The short answer is that you cannot set variable values within a LOAD statement. You can, however, interrogate the loaded data after loading and set a variable based on the outcome. For example:

MyTable:

LOAD models,
productColor,
price,
quantity

FROM
items.csv (txt, codepage is 1252, embedded labels, delimiter is ';', msq);

tmp:
LOAD Count(productColor) As WhiteCount
Resident MyTable;

Let productcode = (If(Peek('WhiteCount') > 0, '7231', ''));
...

Drop Table tmp;


Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein