Find values from 2 datatables

Hi,
I have 2 datatable dt1 and dt2. I want to fill the SAP Mapping of dt1 if the Package is found in dt2 with its corresponding SAP Mapping.

dt1:
image

dt2:
image

resultant_dt:
image

Hi @SunnyJha

Try this in Invoke Code activity

For Each row1 As DataRow In dt1.Rows
For Each row2 As DataRow In dt2.Rows
If row1("Package").ToString() = row2("Package").ToString() Then
row2("SAP Mapping") = row1("SAP Mapping")
End If
Next
Next

Regards,

We can create a lookup dictionary, which will concat the group members (e.g. V)

Assign Activity:
dictLK | Dictionary(Of String, String) =

(From d in dt2.AsEnuemerable()
Group d by k=d("Package").toString.Trim into grp=Group
Let smp = String.Join(", ", grp.Select(Function (x) x("SAP Mapping").toString.Trim))
Let t = Tuple.Create(k, smp)).ToDictionary(Function (x) x.Item1,Function (x) x.Item2)

Then use a For each row in DataTable | row in dt1

  • Assign Activity: row("SAP Mapping") = dictLK(row("Package").toString.Trim)

Hi @SunnyJha

Please check the below workflow:
Sequence56.xaml (10.0 KB)

Input.xlsx (10.3 KB)
DT1 and DT2 sheets are two inputs and Output is the output sheet.
image

Hope it helps!!

1 Like

Thank you Parvathy! This worked and was efficient. Thanks to others as well for contributing on this thread.

1 Like

You’re welcome @SunnyJha

Happy Automation

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