Sum if the cost value column larger than 0

Hi,

Hope the following helps you.

dtResult = dt.AsEnumerable.GroupBy(Function(r) Tuple.Create(r("item").ToString,r("code").ToString)).Select(Function(g) dt.Clone.LoadDataRow({g.key.item1,g.key.item2,g.Where(Function(r) Int32.Parse(r("cost").ToString)>=0).Sum(Function(r) Int32.Parse(r("cost").ToString))},False)).CopyToDataTable

dtResult = dtResult.AsEnumerable.Concat(dt.AsEnumerable.Where(Function(r) Int32.Parse(r("cost").ToString)<=0)).CopyToDataTable

Sample20211104-2.zip (8.3 KB)

Regards,

1 Like