How to add specific Columns from one data table to another

I have two data tables Dt1 and DT2
DT1
ID | Name | Section
1 | Sami | A
DT2
Grade | GPA
A+ | 3.4

The final output In DT3 should be like this
ID | Name | Section | Grade
1 | Sami | A | A+

Hi @Sami_Rajput

You can try with merge Data Table activity

Regards
Gokul

Apologies I just edited the question
please take a look

I want to merge specific Column from DT2 to DT1 not all the Columns

Hi @Sami_Rajput

Then You can First use Filter Datatable then you can Use Merge Datatable.

Regards
Loveleet Saini

1 Like

Hi @Sami_Rajput ,

For this Data, we do not have a Key Value that we could use to map the data between the two datatables.

In such a case, we would require an understanding of whether we need to join rows based on the position of the row and whether the number of rows remain the same in both the Datatable.

The method of joining using row positions could be done in the below way :

  1. Add a new Column Position in both the Datatables.
  2. Use a For each Row in Datatable Activity and update the value of Position Column in both the Datatables using an Assign Activity like below :
row("Position") = DT.Rows.IndexOf(row)
  1. After updation of Position Column in Both the Datatables, we could use Join Datatables Activity to join the rows based on the Position column.
  2. Now we have Joined Datatable which consists of columns present in both the Datatables.
  3. Using Filter Datatable Activity or DefaultView.ToTable() we could preseve only the required columns.

Let us know your thoughts on the method.

1 Like

Hi @Sami_Rajput ,

if you want to get value from DT2 against DT1 column value then you need to user below workflow.

Sequence.xaml (12.2 KB)

Thanks,
Rajkumar

@tushar.c2
The document is invalid(Its not opening)
Can you please re check it

@tushar.c2
if I have many rows in DT2 then it will print only the last row every time
How can I handle that scenario

Remove the inner For Each Row and create an index variable for the outer For Each loop. Change the Assign to:

CurrentRow("Grade") = dt2(index)("Grade").Tostring

Note: This only works if both dt1 and dt2 has the same number of rows.

1 Like

@ptrobot
Thank you so much :100:

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