Best way to remove matching column values in two different data tables?

I don’t care if the entire row matches, just if column X matches.



Col_1 | Col_2 
A          1
B          2
C          3


Col_1 | Col_2 
A          3

I’ll want to remove A From DT_1 because it exists in DT_2.

Hi @David_Hernandez2

Give a try witht the following

Assign: Left side a dtResult Type DataTable
Right side: The next code

(From d in dt1.AsEnumerable
Let k = d("Col_1").toString.Trim.ToUpper
Where Not dt2.AsEnumerable.Any(Function (d2) d2("Col_1").toString.Trim.ToUpper.Equals(k))
Select r = d).CopyToDataTable



Try this in assign …

Dt1 = Dt1.AsEnumerable.Where(function(x) Not dt2.AsEnumerable.Select(function(y) y("Col_1").ToString).ToArray.Contains(x("Col_1").ToString)).CopyToDataTable


Possible to do in C#?


Please try this

Dt1=Dt1.AsEnumerable().Where(x => !dt2.AsEnumerable().Select(y => y["Col_1"].ToString()).ToArray().Contains(x["Col_1"].ToString())).CopyToDataTable()


dt1.AsEnumerable().Except(dt2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable;

Handling empty result:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

1 Like

Blessed, thank you.

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