Subtract the value with respect to there broker account and instrument


Its Here input

Want above output how to do with linq or other logic

@Sohil_bagwan1

You can use this

(From d in DataTableOrigVar.AsEnumerable
Group d by k=d("BrokerAccount").ToString.Trim,k1= d("Instrument").ToString.Trim into grp=Group
Let od = grp.OrderBy(function(x) CDBL(x("Amount").ToString))(0)("Direction").ToString
Let am = (CDBL(grp.OrderBy(function(x) CDBL(x("Amount").ToString))(1)("Amount").ToString) -  CDBL(grp.OrderBy(function(x) CDBL(x("Amount").ToString))(0)("Amount").ToString)).ToString
Let ra = new Object(){k,k1,am,od}
Select r =dtResult.Rows.Add(ra)).CopyToDataTAble

Dtresult is the output datatable with 4 columns and string type

And dataTableorigvar is the input datatable

Cheers