How can I get the count of Duplicates I have in a DataTable

Hello Everyone… :pray:

I have a Datatable Dt_1 as shown below…

Product Name Invoice Code
Microsoft 0204003012/WC/19185020018552
Microsoft 0204003012/LD/19174006010356
Microsoft 0204003012/DP/GIS/557480
Microsoft 0204003012/IF/GIS/585362
Microsoft 0204003012/IF/GIS/585400
Microsoft 0204003012/IF/GIS/586657
Microsoft 0204003012/IF/GIS/586772
AZURE 0204003012/IF/GIS/585396
AZURE 0204003012/LD/19174006010359
AZURE 0204003012/DP/GIS/557645
VMWare 0204003012/WC/19185020018553
VMWare 0204003012/WC/19185020018552
VMWare 0204003012/LD/19174006010356
VMWare 0204003012/DP/GIS/557480
VMWare 0212/RC/9999005180667

Here I want the count of ‘Invoice Codes’ of each product which has ‘GIS’. As shown below…

Product Name Invoice Code
Microsoft 5
VMWare 1

I have tried using for each loop, but it is taking more time to excute the process.

Can any one help me out of this without for each loop.

Thanks in Advance…


prepare a datatable for the result with build datatable: dtResult
2 cols: ProductName, Count

Assign Activity:
dtResult =

(From d in dtDataVar.AsEnumerable
Group d by k=d("Product Name").ToString.ToUpper.Trim into grp=Group
Let cnt = grp.Where(Function (x) x("Invoice Code").toString.ToUpper.Contains("GIS")).Count
Let ra = new Object(){k,cnt}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable


Thanks a lot… :pray:

It helped me…

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