Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
yashfreaky
Contributor
Contributor

How to get max value of date from 4 columns?

Hello Talend Developers,

How to get max value of date from 4 columns? and if visit2 have max date then that row have to be deleted.

 

i/p:

id|name|visit1|visit2|visit3|visit4

1|yash|15-01-2019|10-05-2019|31-01-2019|02-01-2019

2|avin|30-01-2019|10-01-2019|05-01-1019|03-01-2019

3|seth|10-01-2019|15-01-2019|09-01-2019||02-01-2019

 

o/p:

id|name|latestvisit

1|yash|31-01-2019

2|avin|30-01-2019

 

Please let me know how to get that o/p.

Thanks and Regards

Yashwanth Basetty

Labels (2)
1 Solution

Accepted Solutions
ThWabi
Creator II
Creator II

Hello Yashwanth,

 

here is one solution:

0683p000009M2Cm.pngtMap

I hope it's readable. 😉

Compare visit2 last, because then you can determine if it is the maximum date and filter on it.

 

Best regards,

 

Thomas

View solution in original post

3 Replies
ankit7359
Creator II
Creator II

Hi @yashfreaky ,

you can use TalendDate.compareDate method to compare the dates.

 

Thanks,

Ankit.

ThWabi
Creator II
Creator II

Hello Yashwanth,

 

here is one solution:

0683p000009M2Cm.pngtMap

I hope it's readable. 😉

Compare visit2 last, because then you can determine if it is the maximum date and filter on it.

 

Best regards,

 

Thomas

Anonymous
Not applicable

Hi,

 

    Please try below logic.

0683p000009M2LT.png

 

The expression filter will remove any records where visit2 is maximum value. The expression in visit column will pick the maximum among other three values.

 

I have written the logic quickly. So I would suggest you to thoroughly check all combinations and if there are any issues, please make appropriate changes.

0683p000009M2LY.pngtMap

Expression Condition is as below.

 

TalendDate.compareDate(row1.visit2,row1.visit1,"dd-MM-yyyy")>=0?   (TalendDate.compareDate(row1.visit2,row1.visit3,"dd-MM-yyyy")>=0?
    (TalendDate.compareDate(row1.visit2,row1.visit4,"dd-MM-yyyy")>=0?false :true) :true):true

The condition to be used in column is as below.

 

TalendDate.compareDate(row1.visit1,row1.visit3,"dd-MM-yyyy")>=0?
    (TalendDate.compareDate(row1.visit1,row1.visit4,"dd-MM-yyyy")>=0?row1.visit1:row1.visit4)
    :(TalendDate.compareDate(row1.visit3,row1.visit4,"dd-MM-yyyy")>=0?row1.visit3:row1.visit4) 

Hope I have resolved your query. Please spare a second to mark the topic as resolved 🙂

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂