Comparing two Datatable and update new column accordingly

Hi All,
I have two Datatable DT1 and DT2 with one Similar Column called “Active”, I want to Compare matching values from Active column from both DT1 and DT2 and update the new column as Match in DT1, Anyone pls suggest.

Hi @Manii_K

Could you share your Input and Expected output data with us. If the data is Confidential share us the duplicate data with the same columns.

Hi @Manii_K,

You can achieve that as follows via Invoke Code Activity and pass both DT1 and DT2 as in/out parameters.

dt1.AsEnumerable.ToList.ForEach(Sub(r)
r("MatchingOrNot")=If(dt2.AsEnumerable.Any(Function(r2) r("Active").ToString=r2("Active").ToString),"Matching","Not Matching")
End Sub
)

You can refer to the similar solution shared by @Yoichi:

Hi @Manii_K ,

  1. Add New Column to DT1:
    Use an Add Data Column activity to add a new column named “Match” to DT1.
  2. Use For Each row: For each row in DT1
  3. Assign Activity with LINQ Query:
    Use an Assign activity Inside for each row to update the “Match” column in DT1 based on the comparison.

    row("Match") = DT2.AsEnumerable().Any(Function(r) r.Field(Of String)("Active") = row.Field(Of String)("Active"))

This is called a join, it’s a standard database operation. Use the Join Data Table activity.

Thanks Its working as expected

1 Like

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