Group Data Table by Names and count Statuses

Hello, I have a Data Table with two columns, Name and Status. Names can be repetitive, which I want to group. Statuses have 8 different values (Cancelled, Failed, In Progress, On Hold, Open, Passed, Ready, and Ready For Review). I grouped by names using:
(From p In dt_RemoveDuplicates.Select() Group p By ID=p.Item(“Name”).ToString Into Group Select Group(0)).ToArray.CopyToDataTable()

I cloned the DT and made 8 new columns of , but am unsure how to get the count of each status in each group (Cancelled, Failed, In Progress, On Hold, Open, Passed, Ready, and Ready For Review).

Hi,

Hope the following sample helps you.

arrStatus = {"Cancelled","Failed","In Progress","On Hold","Open","Passed","Ready","Ready For Review"}

Then

dtResult = dt.AsEnumerable.GroupBy(Function(r) r("Name").ToString()).Select(Function(g) dtResult.Clone.LoadDataRow({g.Key,""}.Concat(arrStatus.Select(Function(s) g.Count(Function(r) r("Status").ToString=s)).Select(Function(i) i.ToString)).ToArray,False)).CopyToDataTable()

Sample20220812-3.zip (9.6 KB)

Regards,

Thank you so much, appreciate it a lot.

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