Marian_B
(Marian)
March 10, 2022, 12:11pm
1
Hello everyone
I trying to use the “group by” function
Its working for only on column. which way I can add the control also on the second column?
Dt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“Col1”)).Select(Function(g) g.First).CopyToDataTable
Gokul001
(Gokul Balaji)
March 10, 2022, 12:12pm
2
Hi @Marian_B
Try this expression
Dt.AsEnumerable().GroupBy(Function(r) Tuple.Create(r("colName1"),r("colName2"))).Select(Function(g) g.First).CopyToDataTable
Regards
Gokul
3 Likes
Hi @Marian_B ,
I’m not entirely sure what the expected output is, but if you want to group based on two columns, here you go:
Dt.AsEnumerable().GroupBy(Function(i) Tuple.Create(i.Field(Of String)(“Col1”),i.Field(Of String)(“Col2”))).Select(Function(g) g.First).CopyToDataTable
Kind Regards,
Ashwin A.K
1 Like
Marian_B
(Marian)
March 10, 2022, 12:14pm
4
Thanks for Quick reply
I need to group the Two columns @ashwin.ashok
Hi @Marian_B ,
Below is another way to Group By Two Columns :
Dt.AsEnumerable().GroupBy(Function(i) New With {Key .col1 = i("Col1").ToString, Key .col2 = i("Col2").ToString}).Select(Function(g) g.First).CopyToDataTable
1 Like
Hi @Marian_B ,
If that is the case, then the above code should do the trick.
Is there anything specific that you are looking for?
Like an operation after Grouping data?
We can help you out there as well.
Kind Regards,
Ashwin A.K
ppr
(Peter Preuss)
March 10, 2022, 12:22pm
7
(From d in dtData.AsEnumerable
Group d by k1=d(YourColNameOrIndex).toString.Trim, k2=d(YourColNameOrIndex).toString.Trim intogrp=Group
Select r = grp.First()).CopyToDataTable
This HowTo introduces on the different options for grouping data from a datatable in order to process the grouped data.
Introduction
Grouping data and processing the grouped data is a common scenario e.g. when the grouped data is to aggregate like summing up, find maximum, get the average or concatening items.
Lets have a look on following data:
[grafik]
A possible scenario could be:
Create a report containing following information:
the region code
the sum of CaseCount per RegionCode
t…
1 Like
Marian_B
(Marian)
March 10, 2022, 12:27pm
8
No, only i need to group two or more column.
I will check all the expression @ashwin.ashok @Gokul001 @supermanPunch @ppr and let you know
1 Like
Marian_B
(Marian)
March 11, 2022, 5:19am
9
system
(system)
Closed
March 14, 2022, 5:19am
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.