Linq query group by

I want to get count of repeating values in my datatable, preferably using linq query because there are a lot of rows.
I think I can get it using the group by function for linq query? so far here’s mine:

(From d In inDT.AsEnumerable
Group d By k=d("ID").toString.trim Into grp=Group
Let A = New Object(){k, <count here?>}
Select outDT.Rows.Add(A)).CopyToDataTable

So far, I have successfully grouped all ID’s only, but not sure how to get the count or the syntax. I’m really new to linq query so any help would be greatly appreciated, thanks!

refer below code

	GroupBy(Function(r) r("ID")).
		Dim row As DataRow = outDT.NewRow
		row.ItemArray = {g.Key, g.Count}
		Return row
	End Function


Sorry I’m not really sure of the correct syntax, It’s givving me this error: “lambdas cannot be converted to expression trees”

I’m doing this in assign activity


Check this below workflow, @mimuhrin (11.3 KB)
Hope this may help you :slight_smile:


give a try on:
ensure that the outDT Datatable is created (2 Cols: 1 for the key, 2 for the count)

(From d In inDT.AsEnumerable
Group d By k=d(“ID”).toString.trim Into grp=Group
Let A = New Object(){k, grp.Count}
Select outDT.Rows.Add(A)).CopyToDataTable

You have to use assign activity.
Left side is outDT.
Right side is this code.

try it.