Remove Duplicated Rows using 2 columns

Hi Guys,
I have a problem with datatable activity: I need to remove duplicated rows from original datatable taken from an excel file, using 2 columns (out of 5) as criteria. Now I’m using assign activity as shown below:

dtJPKStatusReportNoDuplicates = dtJPKStatusReport.DefaultView.ToTable(True, “Baza danych”, “Okres do”)

The above is working however as a result I’m receiving datatable that contains only 2 columns (“Baza danych”, “Okres do”) while I need also rest of columns from the original datatable - there should be 5 columns as an final output datatable, is there any solution to this?

Hi @Piotr_Gajewski

Please refer

@Piotr_Gajewski
Welcome to the community

This Expression will help you try this

datatable = datatable.AsEnumerable().GroupBy(Function(a) a.Field(of string)(“columnnname”).ToString).Select(Function(b) b.First()).CopyToDatatable()

Regards
Gokul

please refer: UiPath | Remove Duplicate Rows from Excel | How to delete duplicate rows from Excel in UiPath - YouTube

Best regards
Mahmoud

Thank you all for your quick support! Based on your answers and some additional reserach, I’ve managed to achieve my goal - this is how my final assign activity looks like:

dtJPKStatusReportNoDuplicates = dtJPKStatusReport.AsEnumerable().GroupBy(Function(a) Tuple.Create(a(“Baza danych”).ToString, a(“Okres do”).ToString)).Select(Function(b) b.First).CopyToDataTable()

and it works perfect. It’s removing duplicated rows using 2 columns (“Baza danych” and “Okres do”) and it’s also leaving the rest of the columns from original datatable.

Thank you very much!
Piotr