Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rakeshkumar1890
Creator
Creator

According Plan date and Max or Min Orderdate, Required value in new column

Hi Everyone,

Please help me out with this query.

I need output column with the help of Max PlanOrderDate and AvailableOrderDate (If Equal with previous date : output - "Not changed", If Max with previous date : output - "A", if Min with previous date : output - "B"

KeyOrderSeqAvailableOrderDatePlanOrderDateOutput
A00112020-05-252020-05-18Not Changed
A00122020-05-232020-05-19Not Changed
A00132020-05-232020-05-20Not Changed
A00212020-05-012020-04-25A
A00222020-05-052020-04-26A
A00312020-05-102020-04-25B
A00322020-05-052020-04-26B

 

Kind Regards

 

1 Solution

Accepted Solutions
Taoufiq_Zarra

Hi  @rakeshkumar1890 ,

One solution :

Data:

LOAD * INLINE [
    KeyOrder, Seq, AvailableOrderDate, PlanOrderDate
    A001, 1, 2020-05-25, 2020-05-18
    A001, 2, 2020-05-23, 2020-05-19
    A001, 3, 2020-05-23, 2020-05-20
    A002, 1, 2020-05-01, 2020-04-25
    A002, 2, 2020-05-05, 2020-04-26
    A003, 1, 2020-05-10, 2020-04-25
    A003, 2, 2020-05-05, 2020-04-26
];

left join load KeyOrder,
FirstSortedValue(AvailableOrderDate,-Date#(PlanOrderDate,'YYYY-MM-DD')) as Tmp1,
FirstSortedValue(AvailableOrderDate,-Date#(PlanOrderDate,'YYYY-MM-DD'),2) as Tmp2

resident Data group by KeyOrder;

output:
noconcatenate

load 
 KeyOrder, Seq, AvailableOrderDate, PlanOrderDate,
 if(Tmp1=Tmp2,'Not Changed',if(Tmp1>Tmp2,'A','B')) as output
 
 resident Data;
drop table Data;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉

View solution in original post

4 Replies
Taoufiq_Zarra

@rakeshkumar1890 

I don't get it. Can you give an example? for example this line ?

A00112020-05-252020-05-18Not Changed
Regards,
Taoufiq ZARRA

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

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

Hi Taoufiq,

Thanks for approaching to this query.

1. In keyorder A001, You can see that maximum PlanOrderDate is "2020-05-20" and AvailableOrderDate on same row is 2020-05-23 and on Previous PlanOrderDate (2020-05-19), AvailableOrderDate is 2020-05-23

Hence here on both cases AvailableOrderDate are similar - In this case Output should be "Not Changed"

Also you can use Seq for max(3) and Previous(2) in place of PlanOrderDate

2. In keyorder A002, You can see that maximum PlanOrderDate is "2020-04-26" and AvailableOrderDate on same row is 2020-05-05 and on Previous PlanOrderDate (2020-04-25), AvailableOrderDate is 2020-05-01

Hence AvailableOrderDate(2020-05-05 )is greater than Previous AvailableOrderDate (2020-05-01) - In this case output should be "A"

3. In keyorder A003, You can see that maximum PlanOrderDate is "2020-04-26" and AvailableOrderDate on same row is 2020-05-05 and on Previous PlanOrderDate (2020-04-25), AvailableOrderDate is 2020-05-10

Hence AvailableOrderDate(2020-05-05 )is less than Previous AvailableOrderDate (2020-05-10) - In this case output should be "B"

 

Taoufiq_Zarra

Hi  @rakeshkumar1890 ,

One solution :

Data:

LOAD * INLINE [
    KeyOrder, Seq, AvailableOrderDate, PlanOrderDate
    A001, 1, 2020-05-25, 2020-05-18
    A001, 2, 2020-05-23, 2020-05-19
    A001, 3, 2020-05-23, 2020-05-20
    A002, 1, 2020-05-01, 2020-04-25
    A002, 2, 2020-05-05, 2020-04-26
    A003, 1, 2020-05-10, 2020-04-25
    A003, 2, 2020-05-05, 2020-04-26
];

left join load KeyOrder,
FirstSortedValue(AvailableOrderDate,-Date#(PlanOrderDate,'YYYY-MM-DD')) as Tmp1,
FirstSortedValue(AvailableOrderDate,-Date#(PlanOrderDate,'YYYY-MM-DD'),2) as Tmp2

resident Data group by KeyOrder;

output:
noconcatenate

load 
 KeyOrder, Seq, AvailableOrderDate, PlanOrderDate,
 if(Tmp1=Tmp2,'Not Changed',if(Tmp1>Tmp2,'A','B')) as output
 
 resident Data;
drop table Data;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

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

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

Thanks Taoufiq