Compare two datatable

Hi All,

How to compare two dt.
Ex dt1 contain 10 column
Dt2 contain 11 column .
If matching item in dt1 is present in dt2 then ,insert “match” in column 11.if not match then unmatch should be entered.

All 10 column name are same.

1 Like


Please find the xaml file for excel , this will help for solving your problem
Main.xaml (12.8 KB) Test_2.xlsx (9.7 KB)

1 Like

thanks Sanjay, but i am not master in coding so

  1. “dt = dt1.AsEnumerable().Except(dt2.AsEnumerable(), DataRowComparer.[Default]).CopyToDataTable()” i am not understanding. Can you please explain

2)how do i write match/unmatch(in new column) in dt2(sheet 2)

@Palaniyappan can you give your suggestion on my requirements

1.You can use for each row activity,2 for each row activities one inside the other one.
2.Keep one of the data table in outside loop and other in inside loop.
3.Check for the condition in inside loop.
4. If matches then keep like this

1 Like

thanks for reply. but if i have 10 or more column then i have to include all 10 column in if condition .
i was wondering is their any other way

  1. “dt = dt1.AsEnumerable().Except(dt2.AsEnumerable(), DataRowComparer.[Default]).CopyToDataTable()”

This means it will compare both the table(dt1 and dt2) and give you result what is missing in dt2 table, You can take refrence from excel i have attached.

2.You can use merge datatable,Please go throw this link

1 Like


You have already found an elegant solution from the uipath masters, along with that please check following approach.

  1. Use “Filter Data Table” activity to set your filter conditions, it will work on equals, not equals, less than , greater than etc.
  2. This is one stop activity where you can do many number of operations.

However, Using Linq queries would be one of my recommendation.

Sukesh V

dt2 Left join dt1 to dt3
for each row in dt 3:
if 13th~25th columns is null then not match. else match. (use flow chart to judge)
filter dt3 to remove the 13th~25th columns

testTable:2 columns testTable2:3 columns

Here is a detailed article on that :slight_smile: