How to merge datatable rows based on condition

Hi all,

I have one table as:

I want to merge rows which has same id

Expected result:

Is this possible using UiPath studio? Please help…

@Nisha_K21

yes it is possible

Read the data into datatables and then use join datatable activity

cheers

Assign Activity
dtResult | DataType: DataTable = dtOrigVar.Clone

Assign Activity
dtResult =

(From d in dtOrigVar.AsEnumerable
Group d by k=d("id").toString.Trim into grp=Group
let ra1 = grp.First().ItemArray.SkipLast(1).Cast(of Object)
Let tj = String.Join(",", grp.Select(Function (g) g("token"))
Let ra = ra1.Append(tj).toArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

we grouped the data on id and used the aggregated tokens from the groupmembers

Hie @Nisha_K21 you can use join based on email condition
(
From a In dt_2
Join b In dt_3
On a(“Sno”).tostring Equals b(“Sno”).tostring
Select dt_Output.Rows.Add ({a(“Sno”),a(“City”),b(“ZipCode”)})
).copytodatatable

JoinDataTable.zip (2.8 KB)
Hope this Resolve your Query change column as per you requirment and column name
cheers Happy Automation.

Hi @Nisha_K21

=> Use Read Range Workbook to read the excel and store the output in a data table say InputDt.
image

=> Use the below syntax in Assign activity:

OutputDt = (From row In InputDt.AsEnumerable()
 Group row By id = row("id"), name = row("name"), email = row("email") Into Group
 Select InputDt.Clone.Rows.Add(id, name, email, String.Join(",", Group.Select(Function(r) r("token").ToString())))).CopyToDataTable()

OutputDt is of DataType System.Data.DataTable

=> Use Write Range Workbook to write the OutputDt back to excel.
image

FLOW:

XAML:
Sequence12.xaml (8.2 KB)

Hope it helps!!

1 Like

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