Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

LIKE in Conditional IF?

Hello!

I'm trying to do the following in Script:

  • IF:

FLAG_ANOMALY=1

DESCRIPTION LIKE 'SECURITY*'

     Then the value would be No Anomaly for FLAG_DESCRIPTION

  • IF:

FLAG_ANOMALY=1

DESCRIPTION (Other thing than SECURITY*)

     The the value would be With Anomaly for FLAG_DESCRIPTION

  • IF:

FLAG_ANOMALY=0

FLAG_DATE=1

     The the value would be No Anomaly for FLAG_DESCRIPTION

How could I do this? Especially with the "Like".

Thank you!!!

5 Replies
rbecher
MVP
MVP

Hi Mart,

you can use Match() function..

- Ralf

Astrato.io Head of R&D
alexandros17
Partner - Champion III
Partner - Champion III

Try this

IF((FLAG_ANOMALY=1 and wildmatch(DESCRIPTION,'SECURITY*') > 0) or (FLAG_ANOMALY=0 and FLAG_DATE=1) , 'No Anomaly',

     IF(FLAG_ANOMALY=1 and wildmatch(DESCRIPTION, 'SECURITY*') = 0, 'With Anomaly',

'Undefined'

     )

)

let me know ....

anbu1984
Master III
Master III

IF(FLAG_ANOMALY=1, If(DESCRIPTION LIKE 'SECURITY*','No Anomaly', 'With Anomaly'),

IF(FLAG_ANOMALY=0 And FLAG_DATE=1,'No Anomaly')) As FLAG_DESCRIPTION

sarvjeet
Contributor III
Contributor III

There are many ways to implement the solution :

First of all use case satemant instead of multiple IFs

For LIKE  operator qlik provided below functions:

match( str, expr1 [ , expr2,...exprN ] )

The match function performs a case sensitive comparison.

Example:

match( M, 'Jan','Feb','Mar')

returns 2 if M = Feb

returns 0 if M = Apr or jan

mixmatch( str, expr1 [ , expr2,...exprN ] )

The mixmatch function performs a case insensitive comparison.

Example:

mixmatch( M, 'Jan','Feb','Mar')

returns 1 if M = jan

wildmatch( str, expr1 [ , expr2,...exprN ] )

The wildmatch function performs a case insensitive comparison and permits the use of wildcard characters ( * and ?) in the comparison strings.

Example:

wildmatch( M, 'ja*','fe?','mar')

returns 1 if M = January

returns 2 if M = fex

rbecher
MVP
MVP

..or, if FLAG_ANOMALY can only be 0 or 1:

if(FLAG_ANOMALY=1,

  if(wildmatch(DESCRIPTION,'SECURITY*') > 0, 'No Anomaly', 'With Anomaly'),

  if(FLAG_DATE=1, 'No Anomaly', 'Undefined')) as FLAG_DESCRIPTION

Astrato.io Head of R&D