How to perform Group by operation for a specific column in a DataTable and add cities belonging to specific state as a comma separated in single line

Hi @UiPath Community,

Please provide a solution to the below scenario.

Calculate district wise population.
Create input data in Data as below:

input

And required output should be like as below:

Output

@Mahesh5491

I hope the below code will help you

Assign it to Datatable variable

table.AsEnumerable().GroupBy(Function( r) New With {Key
.st = r.Field(Of String)(“State”), Key
.dis = r.Field(Of String)(“District”)
}).[Select](Function( g)
Dim row = table.NewRow()
row(“State”) = g.Key.st
row(“District”) = g.Key.dis
row(“City”) = String.Join(",", g.[Select](Function( r) r.Field(Of String)(“City”)))
row(“Pop”) = g.Sum(Function( r) r.Field(Of Integer)(“Pop”))
Return row
End Function).CopyToDataTable()

I tried assigning above code to data table variable but i’m getting expression expected error. Can you please create workflow because i’m not having any experience related to database in UiPath.

@Mahesh5491

Can you share the data as excel?

Hi @aanandsanraj,

Please find the excel attachment.Population.xlsx (9.0 KB)