Linq query to identify duplicates and delete both entries

Hi, im new to uipath and i am trying to construct a linq query to identify duplicates in a specific column in a datatable then delete both the duplicate and initial datarow. im not too sure where to start.

Hi,

Hope the following expression helps you.

dt = dt.AsEnumerable.Where(function(r) dt.AsEnumerable.Count(function(x) x("Column1").toString=r("Column1").toString)=1).CopyToDataTable()

Regards,

3 Likes

@Charmaine_Matsaudza
Welcome to the forum

find following starter help implementing different scenarios

  • find duplicates by 1 key column
  • find non duplicates by 1 key column
  • find duplicates by 1 Key column and keep first from duplicates + non duplicates

FindDupsUniquesFirstFromGroup_By1Col.xaml (8.0 KB)

3 Likes

Hello Robot Master, thank you for your response. I am getting this error when i open the xaml file you sent. I’m not sure what im doing wrong Screenshot

ensure that you have downloaded into your uipath project and open it from there.
Do not click on Link and do not open the download directly with UiPath

1 Like

Thank you for that, another question , I’m using dtNonDuplicates with the linq from your xaml - (From d In ExtractDataTableOut
Group d By k=d(0).toString.Trim Into grp=Group
Where grp.Count =1
Select grp.First()).CopyToDatatable. Where do i specify the specific column name or index that im checking for duplicates? And also, my intention is to delete the corresponding duplicate row and the first occurrence that duplicate row. Will the linq solve that?

Where do i specify the specific column name or index that im checking for duplicates?
Group d By k=d(YourColNameOrIndex).toSt…

my intention is to delete the corresponding duplicate row and the first occurrence that duplicate row. Will the linq solve that?
here I do unserstand that you are only interested into the NonDuplicated Rows. this is in the demo.

About deletion. The Demo is outputing to dtResult just for inspection reasons. Would overwrite dtData with the result, then it is similar with deletion

1 Like

Oh okay, thank you so much for your help and for bearing with my many questions

@Charmaine_Matsaudza
You are welcome and I am available for additional questions.
Once it is running just provide feedback by marking the solving post as solution. So others can benefit from it.

1 Like

Thank you! I integrated the solution from @ppr and your link query and it worked :smile:

1 Like

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