Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Teja2
Contributor
Contributor

Load using flag field

hi,

i have a table as below 

1)how can i compare old data of ID=PRD858 and set flag as OLD and new ID=PRD858 and set flag as NEW

2)only ID=PRD858  & Purchsed_Date=23/6/20 should be old remaining data should refer as NEW

Please help 

IDProductPurchased_DateRegionSalesFlag
PRD258Pen Drive04-02-20N160OLD
PRD358Mobile23-09-20E161OLD
PRD458Harddisk17-01-20S164OLD
PRD558Pen Drive16-05-20W134OLD
PRD658Mobile05-10-20N135OLD
PRD758Harddisk07-05-20E162OLD
PRD858Pen Drive23-06-20S131OLD
PRD858Pen Drive01-01-21S131NEW
PRD958Mobile07-02-20W148OLD
PRD1058Harddisk22-11-20N142OLD
PRD1158Harddisk21-06-20E136OLD
PRD1458Mobile02-02-21N121NEW
3 Replies
Saravanan_Desingh

As per #2, the first record should not be OLD right?

Sorry I could not understand your requirement

Teja2
Contributor
Contributor
Author

hai sorry for confusion

old record ID prd858 purchased date 23/06/20 should record as old and
ID prd858 purchased date 01/01/21 should show as new and all remaining
records should record as new as well
MayilVahanan

Hi Teja2,

May be try like below


Temp:
LOAD * INLINE [
ID, Product, Purchased_Date, Region, Sales
PRD258, Pen Drive, 04-02-20, N, 160
PRD358, Mobile, 23-09-20, E, 161
PRD458, Harddisk, 17-01-20, S, 164
PRD558, Pen Drive, 16-05-20, W, 134
PRD658, Mobile, 05-10-20, N, 135
PRD758, Harddisk, 07-05-20, E, 162
PRD858, Pen Drive, 23-06-20, S, 131
PRD858, Pen Drive, 01-01-21, S, 131
PRD958, Mobile, 07-02-20, W, 148
PRD1058, Harddisk, 22-11-20, N, 142
PRD1158, Harddisk, 21-06-20, E, 136
PRD1458, Mobile, 02-02-21, N, 121
];

Join
Load PD where NoOfProd = 2;
Load ID, Max(Purchased_Date) as PD, Count(Product) as NoOfProd Resident Temp
Group by ID;

Final:
Load *, If(Purchased_Date >= PD, 'NEW', 'OLD') as Flag Resident Temp;

DROP Table Temp;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.