Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If And Statement

I am struggling in writing an if and statent in qlikview. I am used to doing it in sql but it's different.

I want to say

If field1 = 'yes' and field2 = 'yes' then 'match' or

If field1 = 'yes and field2 = 'no' then 'match1' or

If field1 ='no and field2 = 'yes' then 'match2'

Else 'no match'

Is this possible in qlikview.

I have tried using match and wild match but don't seem to get the and and or working

5 Replies
sunny_talwar

May be this

If(field1 = 'yes',

     If(field2 = 'yes', 'match', 'match1),

     If(field2 = 'yes', 'match2', 'no match')) as MatchFlag

Anil_Babu_Samineni

With in Qlik we can achieve anything.. Perhaps this?

If(field1 = 'yes', If(field2 = 'yes', 'match', 'match1), If(field2 = 'yes', 'match2', 'no match'))


OR


If(field1 = 'yes' and field2 = 'yes', 'match', If(field1 = 'yes' and field2 = 'no', 'match1', If(field1 ='no' and field2 = 'yes', 'match2', 'no match')))

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
its_anandrjs

Try this may be matches with your requirement

if(field1 = 'yes' and field2 = 'yes', 'Match',

if(field1 = 'yes' and field2 = 'no','Match1',

if(field1 = 'no' and field2 = 'yes','Match2'))) as logicField

svinnakota
Creator
Creator

Hi Sarah,

If condition in qlik is similar to case condition in SQL. Just compare the below syntax with case condition. The code is for the script level.

case when field1 = 'yes' and field2 = 'yes' then 'match'

when field1 = 'yes and field2 = 'no' then 'match1'

when field1 ='no and field2 = 'yes' then 'match2'

Else 'no match' end in SQL

In Qlik instead of when we will keep ","(commas)

If (field1 = 'yes' and field2 = 'yes' , 'match' ,    ------- case when field1 = 'yes and field2 = 'yes' then 'match' when

If( field1 = 'yes and field2 = 'no' , 'match1' ,     ----------              field1= 'yes' and field2 ='no' then 'match1' when

If (field1 ='no and field2 = 'yes' ,'match2',        --------------    field1 ='no and field2 = 'yes'  then 'match2' else

'no match' )))                                                                                   'no match'  end

Make sure all the open braces are closed.

its_anandrjs

Hi Sarah,

You can do this on the loading script or else UI part on the Qlikview.

On Load Script

Load

if(field1 = 'yes' and field2 = 'yes', 'Match',

if(field1 = 'yes' and field2 = 'no',  'Match1',

if(field1 = 'no'  and field2 = 'yes', 'Match2','no match'))) as logicField

From Source;

On Ui part you can use but perhaps you can select suppress when values is null() but care ully you have to do this.

On UI Part

if(field1 = 'yes' and field2 = 'yes', 'Match',

if(field1 = 'yes' and field2 = 'no',  'Match1',

if(field1 = 'no'  and field2 = 'yes', 'Match2','no match')))



Note:- If result not matched you can go for the multiple Preceding load or Concatenation between loads or tables


Find the attached Manual from Qlik Help

https://help.qlik.com/en-US/qlikview/12.1/Subsystems/Client/Content/Scripting/ScriptControlStatement...