GroupBy Datatable using LINQ UiPath


Hello, I want to group by the top table → bottom table. But I don’t know how to group it.
I try but it not work as my expect

(From p In VoucherDT.AsEnumerable()
Group By
x = New With { Key.a = p.Item(“Manager Account”)}
Into Grp = Group
Select VoucherApprovedDT_GroupBy.LoadDataRow (New Object() {Grp(0),
String.Join(“,”,Grp.Select(Function(c) c(“Request Account”))),
String.Join(“,”,Grp.Select(Function(c) c(“Request Date”))),
String.Join(“,”,Grp.Select(Function(c) c(“Voucher No”))),
String.Join(“,”,Grp.Select(Function(c) c(“Voucher Type”))),
String.Join(“,”,Grp.Select(Function(c) c(“Amount”))),
String.Join(“,”,Grp.Select(Function(c) c(“Status”)))}, False)).CopytoDatatable

outputDataTable = dt.AsEnumerable().GroupBy(Function(x) x(“ColName”).ToString)[Select](Funtion(y) y.First()).CopyToDataTable()

please follow the following query

1 Like

Hi @Dang_Ngoc_Duy_DPS.VN.MSG

You can proceed like this

image

The LINQ query used is given below

(
	From row In dt_Data
	Group row By k=row("Manager Account").ToString.Trim
	Into grp=Group
	Select dt_GroupedData.Rows.Add({k, String.Join(", ",grp.Select(Function(gr) String.Join("-",gr.ItemArray)))})
).CopyToDataTable

Please read the post by @ppr

Xaml File for reference

GroupByUsingLINQ.xaml (6.6 KB)

1 Like

Thank you for your help

Thank, it work, you save my day ^^

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