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

compare value to list error

I'm trying to compare a variable to match a list, something like 'IN' in SQL.

How do I create a variable containing  a list, and how to I compare a certain variable with 1 string to the list variable and check whether it is in the list.


is this correct?


let vTest = '1;2;3';

let vTemp= '1';


if match ('$(vTemp)','$(vTest)')  then




regards,


Boris

4 Replies
swuehl
MVP
MVP

Your list of values in the match functions needs to be delimited by a comma, and you need to take care of quotation when comparing strings.

So this should work:

Set vTest = "'Aa','B','C'";

Set vTemp= "'Aa'";

IF Match ($(vTemp),$(vTest))  then

  TRACE Success;

ELSE

  TRACE NOSUCCESS;

ENDIF;

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

You can do this with

     If index(vTest, vTemp) > 0 Then

     or

     If index(';' & vTest & ';', ';' & vTemp & ';') > 0 Then     //(exact matches)

But if you need to use match, then:

let vTest = '1;2;3';

let vTemp = '1';

Let vList = chr(39) & Replace(vTest, ';', chr(39) & ',' & chr(39)) & chr(39);

If Match(vTemp, $(vList)) Then

Note that there are NO quotes in the Match expression, they have been added beforehand (chr(39))

HTH

Jonathan

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

The list is created by a load script in which I add to this list ID numbers from a table.

  TempList:

  LOAD concat(RUN_ID,',') as RUN_IDList

  from 'c:\DATA_TABLE.qvd' (qvd)

  let vRunIdList=peek('RUN_IDList',0,TempList);

Any recommendations to this list creation? and to the match function?

Thanks,

Not applicable
Author

Try with WildMatch function like below:

let vTest = '1;2;3';

let vTemp= '1';


if WildMatch('$(vTemp)','$(vTest)')  then