Group by multiple columns in data table and get count of one column and select rest of the non grouped columns

Hi , I need to group by three columns(name,class,leave) and count the values in “leave” column and add the values in last column as well as i need to get other non grouped columns.

@lk_18
welcome to the forum

have a look here as well:

Clone datatable: dtResult = dtDataTableVar
Add a new column to dtResult - Add DataColumn Activity - ColumnName: count

Assign Activity
Left Side: dtResult
Right side:

(From d in dtDataTableVar.AsEnumerable
group d by k1=d("Name").toString.Trim(),k2=d("Class").toString.Trim(),k3=d("Leave").toString.Trim() into grp=Group
let f = grp.First()
let ra = new Object(){f(0),k1,k2,f(3),k3,grp.Count}
Select dtResult.Rows.add(ra)).CopyToDataTable

Thank you. its working as per my need

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