How to Merge Two Data table

Hi there,
I’m try to merge two dt Like below ScreenShot

Any idea??

Please follow the below approach:

  1. Create a new data table using the Build Data Table activity
  2. Use 2 nested For Each Row inside one another and iterate through both of your data tables
  3. Use an if condition to check if the values in Col 1 match like ARow("Col1").ToString = BRow("Col1").ToString
  4. If it matches (inside then block): do null checks on Col 2, Col 3, and based on that decision, pass the available value to your new data table using Add Data Row activity

This is a simple way to achieve this. You can also use counter logic to filter rows from both data tables and then use the results to frame a new output data table.

Cheers!

1 Like

Hi @Peace_Maker

To merge two data tables in UiPath, you can use the Merge Data Table activity. This activity allows you to merge two data tables by specifying the data table to merge and the data table to merge into, as well as the columns to use for the merge.

Here’s an example of how you can use the Merge Data Table activity in a UiPath workflow:

  1. Drag and drop the Merge Data Table activity onto the design canvas.
  2. In the Data Table to Merge field, specify the data table that you want to merge into the other data table.
  3. In the Data Table to Merge Into field, specify the data table that you want to merge the other data table into.
  4. In the Merge Columns field, specify the columns that you want to use for the merge. You can specify multiple columns by separating them with a comma.

You can also use the Merge Data Table activity to specify the type of merge to perform (e.g. inner, outer, left, right), as well as the columns to use for the merge key.

Reference Link: https://docs.uipath.com/activities/docs/merge-data-table

Thanks!!!

Hi,

Hope the following sample helps you.

dtA = dtA.AsEnumerable.Zip(dtB.AsEnumerable,Function(r1,r2) dtA.Clone.LoadDataRow(r1.ItemArray.Zip(r2.ItemArray,Function(v1,v2) if(String.IsNullOrEmpty(v1.ToString),v2,v1)).ToArray,False)).CopyToDataTable

Sample20221222-3aL.zip (2.9 KB)

Regards,

5 Likes

Hi,
you can use For Each Row to iterate through DataTable A and then use .select to find the matching row in DataTable B:
DataTable B.Select("Col1 = ’ “+row.item(Col1)+” ’ ")(0)(“Col2”) → this should give you the value in Col2 in DT B in the same row as in DT A. Now you need some if conditions, which value you want to have.

Regards
Moritz

1 Like

what to update in Col3 for Result table, when there is data in Col2 of both of the table (DataTable A and DataTable B)…?

  1. Do we need to sum and update in Col3 or
  2. Update exception comment ?

Actually there is no way both cell have value
So no worry about it :slight_smile:

1 Like

Merge Data Table cannot handle my problem :cry:

check @Yoichi’s solution, I think that will work for you.

1 Like

Thank you! you really help me a lot ^^

1 Like

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