Group data and sum only one of the groups in excel

I agree to Arpan
when we group with above LINQ we get in the result all distinct Idnumbers with its sums

When for any reason the grouping /summing up is to do along with a filter restriction to only 100 we can do:

strFilter = “100”

dtResult =

(From d in dtData.AsEnumerable
Group d by k=d("idnumber").toString.Trim into grp=Group
Where k.Equals(strFilter)
Let s = grp.Sum(Function (x) Convert.ToDouble(x("amount").toString.Trim))
Let ra = new Object(){k, s}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

But here we should handle the empty filter result also as described here:

As an alternate we can also create a dictionary for all idnumbers and sums as by following:

dictLK | Dictionary (Of String, Double) =

(From d in dtData.AsEnumerable
Group d by k=d("idnumber").toString.Trim into grp=Group
Let s = grp.Sum(Function (x) Convert.ToDouble(x("amount").toString.Trim))
Let ra = new Object(){k, s}
Select  t  = Tuple.Create(k,s)).ToDictionary(Function (t) t.Item1,Function (t) t.Item2) 
2 Likes