How to compare two datatable based on two column

Hi ,
Please help me with below situation,
Dt1=
ID Name Comment ExtraColumns…
1 A Present
2 B Absent
3 C Present

Dt2=
ID Name Previ.Comment
1 B
1 A
2 B
2 C
2 D
3 C

Expected Output
Dt2=
ID Name Previ.Comment
1 B
1 A Present
2 C
2 D
2 B Absent
3 C Present

Nesting for each i can get the output but is their any other efficient way

1 Like

Hey @TUSHAR_DIWASE

Kindly use Join Data Table activity, with props as below

Data Table 1 - DT2

Data Table 2 - DT21

Type - Left Join

Set the columns ID & Name in the condition.

Thanks
#nK

Hi NithinKrishna,

Thanks for the reply but it is not helping.
i forgot to mention that their is some more column . because of those column outout is not coming correctly

1 Like

Hey @TUSHAR_DIWASE

Any sample excel if you can share, so that a demo workflow can be created which may help you.

After you get the result from the Join data table, you can just use default view for extracting only specific columns.

DT_Input.DefaultView.ToTable(true, {"ID", "Name ", "Previ.Comment"})

Thanks
#nK

Sorry for delay.
Please find attachment with Dt1,Dt2 and expected output
Test.xlsx (9.4 KB)

1 Like

Hi @TUSHAR_DIWASE ,

Welcome to UiPath Community :slight_smile:.

Please find attachment for the solution and also the excel file with output in Sheet1.
Test.xlsx (11.1 KB)
Sequence1.xaml (10.6 KB)

If this is what you required mark it as solution.

Happy Learning,
Achal Sharma

Thanks @Achal_Sharma for the response.
I already implemented solution using nesting if. But i am looking for other efficient way

Join datatable activity canbe used for this
the final output we get by postprocessing the Join result

Hey @TUSHAR_DIWASE

Please find the demo code for you below,

nmnithinkrishna_CompareDTWithTwoColVal.zip (11.5 KB)

Hope this helps

Thanks
#nK

3 Likes

Thanks @Nithinkrishna.
Last question from my end,currently it is 4 column only but if their is 30 column then i guess it is not good to write all column name into default view.

1 Like

Hey @TUSHAR_DIWASE

Yes Of course. you are right.

You can try the below for dynamic field mapping

dt_Data.Columns.Cast(Of DataColumn).Select(Function(dataCol) dataCol.ColumnName).ToArray

The above query will fetch all the columns from a datatable.

Thanks
#nK

1 Like

HI @Nithinkrishna
thanks for quick feedback but after using suggested query , output dt column reformatting is not working.
reformating

1 Like

Hey @TUSHAR_DIWASE

You need the columns from DT1 or DT2 ?

Thanks
#nK

@Nithinkrishna all column from dt2.
sometime their will will many column in dt2.
we have to match 2 column from dt1 to dt2. if match found then dt2 will be updated with commwnt from dt1

1 Like

Hey @TUSHAR_DIWASE

Please find the update for the same,

nmnithinkrishna_CompareDTWithTwoColVal_v2.zip (12.4 KB)

Thanks
#nK

@Nithinkrishna thank you so much for the help. Result is all good.
really appreciate

1 Like

Cool @TUSHAR_DIWASE

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