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

Multiple if's not working as expected

Hello Qlik Folks,

Why can't I write multiple if's like this, only 1st statement is working as expected.

if(len(trim([Begin Date]))=0 and len(trim([End Date]))=0, 'Closeouts','Excl Closeout'),
if(len(trim([Begin Date]))>0 and len(trim([End Date]))>0, 'Closeouts','Excl Closeout')
as CloseoutDesc

expected output attached  

 

1 Solution

Accepted Solutions
mrybalko
Creator II
Creator II

You should write nested ifs like this:

if(condition 1, true,
   if(condition 2, true, false)) as field1

Your case

if(
     (len(trim([Begin Date]))=0 and len(trim([End Date]))=0) // 1 condition
     OR 
     (len(trim([Begin Date]))>0 and len(trim([End Date]))>0), // 2 condition
'Closeouts','Excl Closeout') as CloseoutDesc

 also you can use >= operator and simplify if

if(len(trim([Begin Date]))>=0 and len(trim([End Date]))>=0,  'Closeouts','Excl Closeout') as CloseoutDesc

View solution in original post

4 Replies
m_woolf
Master II
Master II

Unless I'm missing something, your second IF is exactly the same as the first and will never be executed.

Try:

if(len(trim([Begin Date]))=0 and len(trim([End Date]))=0, 'Closeouts','Excl Closeout') as CloseoutDesc

mrybalko
Creator II
Creator II

You should write nested ifs like this:

if(condition 1, true,
   if(condition 2, true, false)) as field1

Your case

if(
     (len(trim([Begin Date]))=0 and len(trim([End Date]))=0) // 1 condition
     OR 
     (len(trim([Begin Date]))>0 and len(trim([End Date]))>0), // 2 condition
'Closeouts','Excl Closeout') as CloseoutDesc

 also you can use >= operator and simplify if

if(len(trim([Begin Date]))>=0 and len(trim([End Date]))>=0,  'Closeouts','Excl Closeout') as CloseoutDesc
dseelam
Creator II
Creator II
Author

difference > & = to signs on both the if's

dseelam
Creator II
Creator II
Author

Awesome this is what am exactly looking for