Could you also show us what is the Output you are receiving currently and How do you want the Output to be ? Do you only want the Sum value corresponding to Id Number 100 or do you need it in a row/Datatable format ?
If you need only the Sum, then you could try the below :
The group by you have used will get all the unique item of id’s and the sum of the amount column based on the I’d
If you want to add only value 100 you can check with @supermanPunch suggestion
And also you try the following
After using the group by you have used
You can use lookup datatable activity to search for value 100 and get target column cell value 1869
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)