Join Two Data tables with Different Columns and Different Data

If I need to join two data tables with different-different column names and different-different data?
or
I want to join two data tables without any conditions.

  • I have the first Data Table dt_FirstDataTable with two columns Name, City.

    image

  • I have the second Data Table dt_SecondDataTable with two columns Phone, Age.

    image

  • I want a final table with all columns value Name, City, Phone, Age. So what can I do?

    image

Solution: -

  • We have to create a String-type array variable to store the data table columns name.

  • Write a Syntax to get data table columns’ names into an Array variable.

(from name in dt_SecondDataTable.Columns.Cast(of DataColumn)Select name.ColumnName).ToArray

  • We have to add a second data table (dt_SecondDataTable) column into the first data table (dt_FirstDataTable) without column values with the help of For Each loop and Add Data Column Activity.

  • With the help of For Each Row in Data Table activity, we have to add a second data table (dt_SecondDataTable) column value into the first data table (dt_FirstDataTable).

  • Here we have to get the Index value for Second Data Table.

  • With the help of For Each loop activity, BOT will add a second data table value one by one in the first data table.

Use the Information and enjoy Automation.

Thanks
Ankit Kumar

1 Like

Hello @Ankit_Chauhan

It’s the same as adding the datatable to nearby columns ryt? You can use the Append range and write to the first 2 columns and then the second datatable starting from C2.

Thanks

HI @Ankit_Chauhan

Give it a try like this

  • Read range first dt and second dt store them as dt1 and dt2
  • Write range the second dt (i.e., dt2) in the place of first dt you need to write in the cell next to the last column of first dt you need to give the cell value as
    UiPath.Excel.Helpers.ExcelUtilities.ConvertColumnIndexToColumnLetter(dt1.Columns.Count+1)+“1”

Ref Xaml file


WithDataTable.xaml (12.9 KB)

or

Check out these links

Regards
Sudharsan

@Ankit_Chauhan this can be possible by creating a key_column by add data column activity in both of the data table , then join both the data table using the created key.

Here find attachment:

JoinData.zip (2.3 KB)

It will not work, I tried already.