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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
surajap123
Creator III
Creator III

conditonal load

Hi Experts

I want to conditionally load the table based on values in variable.

I have the below variable that contain the list of values.

LET vSegTypes = chr(39) & Peek('Customers') & chr(39);

I want to compare the above values with below variables.

SET vVar1 = No1;

SET vVar2 = No2;

SET vVar3 = No3;

if ($(vSegTypes) = $(vVar1)) or ($(vSegTypes) = $(vVar2)) or ($(vSegTypes) = $(vVar3)) then

  

     load ....from;

  end if

The above if condition is not working. Please help.

Labels (1)
1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

On seeing your error, it looks like you are concatenating multiple values in to a variable 'vSegTypes'

in that case I prefer to use Match function

Try something like this

IF Match('$(vVar1)', $(vSegTypes)) or Match('$(vVar2)', $(vSegTypes)) or Match('$(vVar3)', $(vSegTypes)) then

    load ....from;

  end if

View solution in original post

9 Replies
sunny_talwar
MVP
MVP

Try this may be:

IF $(vSegTypes) = '$(vVar1)' or $(vSegTypes) = '$(vVar2)' or $(vSegTypes) = '$(vVar3)' then

Anonymous
Not applicable

//On peek you need to write the row number and table.

LET vSegTypes = Peek('Customers',NumberOfReg,'Table');

SET vVar1 = No1;

SET vVar2 = No2;

SET vVar3 = No3;

//On IF, put your vars into string

if '$(vSegTypes)' = '$(vVar1)' or '$(vSegTypes)' = '$(vVar2)' or '$(vSegTypes)' = '$(vVar3)' then

  

     load ....from;

  end if

Anonymous
Not applicable

Other option is load table with where condition:

Customers:

Load

     ....

RESIDENT YourTable

WHERE Customers = '$(vVar1)' or Customers= '$(vVar2)' or Customers = '$(vVar3)';

Kind regards

marcus_sommer
MVP
MVP

If you want to access variables which contain string-values you need to wrap them with single-quotes like:

'$(vVar)'

beside them VSegType will be return NULL because peek is applied outside from a load and needs further parameter like: Peek('Customers', RecordNumber, 'Tablename' ) and then it would be only contain a single value and not a list of values. Here you would need to loop through these field and then probably rather in this way:

for i = 0 to fieldvaluecount('Customers')

     let vSegTypes = fieldvalue('Customers', $(i));

     ....

- Marcus

tamilarasu
Champion
Champion

You can also try,

LET vSegTypes =  Peek('Customers') ;


SET vVar1 = 'No1';

SET vVar2 = 'No2';

SET vVar3 = 'No3';

if vSegTypes = vVar1 or vSegType = vVar2 or vSegTypes = vVar3 then


    load ....from;

  end if

surajap123
Creator III
Creator III
Author

Hi Sunny,  Thanks for the reply.

I got the Error: Script line error. I see that the variable has null in 3rd condition.

if 'Field1','Field2' = 'Field5' or

   'Field1','Field2' = 'Field8' or

   'Field1','Field2' = ''  or

   'Field1','Field2' = 'Field10'  then

Error: Script line error:

sunny_talwar
MVP
MVP

Would you be able to share the table form which Customer is coming from?

CELAMBARASAN
Partner - Champion
Partner - Champion

On seeing your error, it looks like you are concatenating multiple values in to a variable 'vSegTypes'

in that case I prefer to use Match function

Try something like this

IF Match('$(vVar1)', $(vSegTypes)) or Match('$(vVar2)', $(vSegTypes)) or Match('$(vVar3)', $(vSegTypes)) then

    load ....from;

  end if

surajap123
Creator III
Creator III
Author

Thanks everyone for the support.