How can I delete rows of negative and positive cells that cancel each other out?

@nibir08
thanks for detailed case description.

Assumptions:
Group Values are the same Value and only different on positive or negative

Variables:
grafik

Flow:
Preperation result DataTable and grouping the data by firtst Column values
grafik

Processing the groups and adding remaining rows to Result Datatable

e.g. getting the posivite values:
(From g In grp
Let x = CInt(g(1).toString.Trim)
Where x > 0
Select r=g).toList

getting the common count:
{PosRows.Count, NegRows.Count }.Min()

Adding remaining rows to result datatable:
(From x In PosRows.Skip(CommonCount).Concat(NegRows.Skip(CommonCount))
Let ra = x.ItemArray
Select dtResult.Rows.Add(ra)).toList

Input / output:
grafik

find starter help here:
GroupBy_1Col_OffsetGrpMembers.xaml (11.9 KB)

For getting more familiar with LINQ have a look here:

1 Like