Join activity

hey, I have two dataTables: DT1: Name, Class, Hobby and DT2: Name, Class I want to join them based on Name and class, and “Hobby”=“Swiming” .

to concule I want to keep all the rows from both DataTables (DT1 and DT2), but only fill the rows where the “Hobby” column is “Swiming”

Hi @BlueBird1

Use the following query in the Assign activity:

JoinedDT = (From row1 In DT1.AsEnumerable()
                            Join row2 In DT2.AsEnumerable()
                            On row1.Field(Of String)("Name") Equals row2.Field(Of String)("Name") And
                               row1.Field(Of String)("Class") Equals row2.Field(Of String)("Class")
                            Where row1.Field(Of String)("Hobby") = "Swimming"
                            Select DT1.Clone().Rows.Add(row1.ItemArray)).CopyToDataTable()

Hope this helps,
Best Regards.

I’ll try it

1 Like

Hi @BlueBird1 ,

Can you provide your input and expected output?

Regards,
Aditya

this is the first input DT1
image

this is the second DT2
image

I want to join them based on Name, and class and Hobby=“Swiming”
image

@adiijaiin

@arjunshenoy I got this errror Error ERROR Validation error (3): error BC30456: ‘AsEnumerable’ is not a member of ‘IWorkbookQuickHandle’. Main.xaml

is this your expected output?
[Name,Class,Hobby,Name_1,Class_1
Cilia,A,Swimming,Cilia,A
Sirine,B,Painting,Sirine,B
]

If you’re joining DataTables there would be 5 columns,
Do you want to Merge it?
Merge would produce only 3 columns.
[Name,Class,Hobby
Cilia,A,
Sirine,B,
Cilia,A,Swimming
Sirine,B,Painting
Assil,C,Swimming

image
this is the output I want

Use this code to get your required output.
TableOperation.xaml (12.3 KB)

Thanks