Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

IF statement is not working as I expected.

Hi,

I do have the below Inline load statement.

testing:
Load * Inline [
Date1, Date2
24/08/2021, 24/08/2021
24/08/2021, 24/08/2021
23/08/2021, 23/08/2021
22/08/2021, 22/08/2021
21/08/2021, 21/08/2021
2999, 4000
2998, 3999
];

Now the requirement is if the date1 is before today it has to be 'Y', remaining dates it has to be 'A' and not relevant date it has to be 'Unknown', same applies for date2 as well.

I tried the below code and it is not working.

Testing_Load:
Load *,
if(date1 < today(),'Y',if(date1<> today(),'A','UnKnown')) as Status1,
if(date2 < today(),'Y',if(date2<> today(),'A','UnKnown')) as Status2,
Resident testing;

Drop Table testing;

Output:

date1date2Status1Status2
29983999YY
29994000YY
21/08/202121/08/2021YY
22/08/202122/08/2021YY
23/08/202123/08/2021YY
24/08/202124/08/2021UnKnownUnKnown

 

Expected Output:

date1date2Status1Status2
29983999UnKnownUnknown
29994000UnKnownUnknown
21/08/202121/08/2021AA
22/08/202122/08/2021AA
23/08/202123/08/2021YY
24/08/202124/08/2021AA

 

Regards,

Vikas

1 Solution

Accepted Solutions
stevejoyce
Specialist II
Specialist II

Testing:

Load
Date1
,Date2
,if(Date1 = today()-1, 'Y', if(isnull(date(date#(Date1))), 'Unknown', 'A')) as Status1
,if(Date2 = today()-1, 'Y', if(isnull(date(date#(Date2)) ), 'Unknown', 'A')) as Status2
;

Load * Inline [
Date1, Date2
24/08/2021, 24/08/2021
24/08/2021, 24/08/2021
23/08/2021, 23/08/2021
22/08/2021, 22/08/2021
21/08/2021, 21/08/2021
2999, 4000
2998, 3999
];

 

View solution in original post

4 Replies
Taoufiq_Zarra

@vikasshana  can you elaborate

2998 are there date or just a number?

why 24/08/2021 is Y 24/08/2021<today() is false ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
vikasshana
Creator II
Creator II
Author

sorry for the confusion, below is the updated requirement.

If the date1 is yesterday it has to be 'Y', apart from yesterday's date all other dates are 'A' and if the irrelevant dates like 2998 it has to be 'Unknown'.

stevejoyce
Specialist II
Specialist II

Testing:

Load
Date1
,Date2
,if(Date1 = today()-1, 'Y', if(isnull(date(date#(Date1))), 'Unknown', 'A')) as Status1
,if(Date2 = today()-1, 'Y', if(isnull(date(date#(Date2)) ), 'Unknown', 'A')) as Status2
;

Load * Inline [
Date1, Date2
24/08/2021, 24/08/2021
24/08/2021, 24/08/2021
23/08/2021, 23/08/2021
22/08/2021, 22/08/2021
21/08/2021, 21/08/2021
2999, 4000
2998, 3999
];

 

vikasshana
Creator II
Creator II
Author

Thanks for the solution Steve, It is working as I expected.