Input

Output

I need help with LINQ where I have to groupby ID and if SUm of AMOUNT is greater than ZERO then retrurn all the rows as shown above
Input

Output

I need help with LINQ where I have to groupby ID and if SUm of AMOUNT is greater than ZERO then retrurn all the rows as shown above
Try this
outputDT = inputDT.AsEnumerable().GroupBy(Function(row) row("id").ToString()) _
.Where(Function(group) group.Sum(Function(r) Convert.ToDecimal(r("Amount"))) > 0) _
.SelectMany(Function(group) group).CopyToDataTable()
Regards,
Give a try at
Assign activity
dtResult =
(From d in dtData.AsEnumerable
Group d by k=d("id").toString.Trim into grp=Group
Let sc = grp.Sum(Function (x) CInt(x("Amount").toString.Trim))
Where sc > 0
From g in grp
Select r=g).CopyToDataTable
Handling empty results:
=> Read Range Workbook
Output → InputDt

=> Use below syntax in Assign:
resultDt = (From row In InputDt.AsEnumerable()
Group row By key = row.Field(Of String)("id") Into Group
Let TotalAmount = Group.Sum(Function(r) r.Field(Of Double)("Amount"))
Where TotalAmount > 0
From r In Group
Select r).CopyToDataTable()
=> Write Range Workbook resultDt back to excel in new sheet.

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