Remove Duplicate Row From Data table using column as the filter criteria

My Input Datatable is -

Emp ID Equipment
772745 V
772743 P
772746 V
772745 P
772743 P
772746 P

Expected Output Datatable should be–

Emp ID Equipment
772745 V
772743 P
772746 V

datatable.DefaultView.Totable(True,{“Emp ID”,“Equipment”}) is not working for this case i tried.

Could you please post the solution using linQ as its processing a huge amount of data.

Yes and its ok becouse if you read Emp ID + Equipment the are not the same

772745 V <-- Is Not Equal to --> 772745 P

Remove duplicates from Emp ID and do a a second lop at Emp ID en for each row if string.isnulorempty delete row

Hello @RajeshCTS

Welcome to the forum, if it’s necesary you can try this out:

(From p in inputDT.Select() where( From q in InputDT.Select() where q(“Emp”).Equals(p(“Emp”)) Select q).ToArray.Count=1 Select p).ToArray.CopyToDataTable()

DistinctRows_LINQ2.zip (8.0 KB)


However you can use remove dup rows activity:


If this answer your question please give it a like and mark it as solved :slight_smile:

Regards

2 Likes

Luis ,

I need to remove duplicate rows (Emp ID should be distinct).Don’t consider the other column.

Have any linQ through which we can do it. Actually its a huge no of rows (60K>) so loop is not recommended

Bees,

It’s not working, its returning same datatable value as output. No filter happening for this.

Could you please send me the file .

So use @ beesheepRobot Apprentice query

or use remove duplicate values activity, becouse your query will not work

test

Directly I am not reading sheet to get this duplicate value in data table. After some data processing only I am getting this duplicate value in data table.

@RajeshCTS Sure thing,

What steps have you done to complete this task, where you able to download the zip I provided you?

If you can share what you have done so far it’s much more feasible to help you :slight_smile:

please come back to us with an XAML.

regards

Duplicate.xlsx (8.1 KB) Main.xaml (6.4 KB)

I am getting below exception and attached is the xaml file for reference

Source: Assign

Message: The source contains no DataRows.

Exception Type: System.InvalidOperationException

RemoteException wrapping System.InvalidOperationException: The source contains no DataRows.

1 Like

@RajeshCTS

Try below expression.

        newDT = datatable.DefaultView.Totable(True,“Emp ID”).CopyToDataTable
1 Like

Hi
welcome to uipath community
You were almost done
The expression be like
Yourdatatable = Yourdatatable.DefaultView.ToTable(true, “Column1”, “Column2” …,”Column n”)
Or we can simply mention like

Yourdatatable = Yourdatatable.DefaultView.ToTable(true, “Column1”)

Even one column duplicate is removed other will be neglected as well

Or to be more precise
Yourdatatablename = Yourdatatablename.AsEnumerable().Groupby(function(a) a.Field(of String)(“yourcolumnname”).Tostring.Toupper).Select(function(b) b.First()).CopyToDatatable()

Hope this would help you
Cheers @RajeshCTS

Could you please check ,this statement is not working as i mention before and its returning only Emp ID column value not the Equipment column value.

My OUTPUT should be —

Emp ID Equipment
772745 V
772743 P
772746 V

:grinning::smiley:This LinQ working as expected . Without String Datatype can we create linQ with generic datatype, may be Emp ID will be double datatype.

I did like this its working fine for all datatype

(From p In dt_input.Select Group p By ID=p(“Emp ID”).ToString into Group Select Group(0)).ToArray.CopyToDataTable

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.