Comparing two DataTables per row

Hi,

I have two DataTables that more or less contain the same information. I would like to see if there is an element missing or added to one of the DataTables.

So if DT1 =

  • Apples
  • Pears
  • Oranges

And DT2 -

  • Apples
  • Pears

I would like it to return that Oranges is missing from DT2.
Anyone that can help?

Thanks!

Hi @VladP

Use if condition

If(row(“column name”).ToString.equals row1(“Column name”).ToString

In else you can return missing element row(“column name”). ToString is missing

Thanks
Ashwin.S

Hey @VladP

Use Join Data Tables for this scenario.

Thanks
#nK

you can use the except() function @VladP

the below code will print out the items in dt1 that are missing in dt2 (separated by comma)

this is assuming your column name = “Fruit”, if not then you have to change it

String.Join(",", dt1.AsEnumerable.Select(function(row) row("Fruit").ToString).ToList.Except(dt2.AsEnumerable.Select(function(row) row("Fruit").ToString).ToList))

1 Like

Hello @VladP

Please refer to the below video. You can find the similar and dissimilar rows from 2 datatables.

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