DT Comparison

Hello all,

I am working with 2 data tables. I am looping through each of them looking for a common column value (LAST NAME) if I find a match, I have to copy the values of 5 different columns for that specific row that matched in DT1 to DT2.

I have the logic to find the common “Last Name” but I am not able to assign the values from the 5 columns in DT1 into DT2. Any suggestions?

Thank you!

@rjackson
If you know the row number to which you want to assign the values then you can use the below method :

Assign
DT2.Rows(row number).Item(“Column name”) = DT1.Rows(row number).Item(“Column name”)

You can also use a counter variable (Eg: i = 0) and then increment it inside the for each row activity.

if (last name matches)
{

DT2.Rows(i).Item(“Column1”) = DT2.Rows(i).Item(“Column1”)
DT2.Rows(i).Item(“Column2”) = DT2.Rows(i).Item(“Column2”)

}

i = i+1

1 Like

Hi there,
Thank you for the response!

Right now I have the following:

  • For each row - DT1
  • For each row - DT2
    IF- Last Name Matches
    Assign Value From Column (x) of DT-1 to Column (y)- DT2

The columns that I am copying from one dt to the other have the same column names. But the number of rows is different from one DT to the other so the counter will be hard to keep track of.

@rjackson
please share some data samples and a detailled description on the expected output. We can help you faster with this on reference. Thanks

Sample.xlsx (11.2 KB)

Please refer to the sample file. There are 2 tabs that will became 2 different DTs. (DT1 and DT2)

If the last name from DT1, matches the last name in DT2, I would need to copy the additional columns from DT1 to DT2. (Gender, Occupation)

I am adding the data columns before both for each loops for each of the files. I would need to copy the values from one DT to the other.

@rjackson
have alook on this activity

it will give as output an intermediate result on which you can iterate and can be used for the data transfer

3 Likes

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