Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
poonam_kulwal
Partner - Creator
Partner - Creator

How to check previous entries in a column

Hi All,

I have a table with Product_ID and Batch_ID. I want to create a Status column that has information regarding if Product_ID is getting repeated or not based on Batch_ID.

   

Product_IDBatch_IDRepeat Status
AA111234No
AA111235Yes
AA111238Yes
AA111256Yes
AB231111No
AR322141No
BE323553No
SD87244No
AA114554Yes
AR322454Yes

I want to generate Repeat status column in my load script.

Any help will be appreciated.

Thanks & regards,

Poonam

5 Replies
sunny_talwar

May be like this

LOAD Product_ID,

     Batch_ID,

     If(Product_ID = Previous(Product_ID), 'Yes', 'No') as [Repeat Status]

Resident ....

Order By Product_ID, Batch_ID;

poonam_kulwal
Partner - Creator
Partner - Creator
Author

Thanks Sunny. I also added RowNo() function in order to keep rows on same position.

Wondering My Product_ID and Batch_ID are alphanumeric fields with very long string.

example "jsfsa3242lkklmsk456j5jnksdfk000000000042320jkk23" like this.

and my qvd size is 1 GB.

Wondering, "order by" will work fine in terms of optimization concern?

Or do I convert my alphanumeric field to something.

Table1:

LOAD RowNo() as Rowno,
  Product_ID,
     Batch_ID       
FROM (ooxml, embedded labels, table is Sheet1);

Table2:
load *, if(previous([Product_ID])=[Product_ID],'Yes','No') as [Repeat Status]
Resident Table1 Order by Product_ID, Batch_ID ASC;
DROP table Table1;

sunny_talwar

If you can correctly sort the data within your Excel file, then you don't have to use the order by clause. Order by is used to make sure that the unsorted data is sorted correctly. Now if you don't have it sorted correctly, there is no better way to do this

Monicalingan
Contributor III
Contributor III

Hi Poonam,

Inline:

LOAD * INLINE [

   

   Product_ID, Batch_ID,

    AA11, 1234

    AA11, 1235

    AA11, 1238

    AA11, 1256

    AB23, 1111

    AR32, 2141

    BE32, 3553

    SD87, 244

    AA11, 4554

    AR32, 2454

    

];

Load * ,  if(Product_ID=peek(Product_ID),'Yes','No') as RepeatStatus

Resident Inline

Order by Product_ID;

Drop table Inline;

Hope this helps.

Thanks,

Monica

poonam_kulwal
Partner - Creator
Partner - Creator
Author

Thanks Sunny.