Linq with if Condition and Datatable Update

In general a Group By Case which we can handle as described here:

We would recommend to start with a hybrid approach

Groups | DataType: List(of (ListOf DataRow)) =

(From d in dtData.AsEnumerable
Group d by k1=d("InvoiceNo.").toString.Trim, k2=d("MATERIAL CODE.").toString.Trim into grp = Group
Select x=grp.ToList).toList

outer List = Groups, inner List = Group Members

For Each Activity (not for each row activity) | grp = Groups | TypeArgument: List(Of DataRow)

  • Assign Activity
    strAVG = grp.Average(Function (x) CDbl(x(“Price”).toString.Trim)).toString(“F2”)

  • For Each Activity (not for each row activity) | mbr in grp | TypeArgument: DataRow

    • Assign Activity: mbr(“Price”) = strAVG

When DataColumn Price defines a Not Object/String Datatype then we just would little adapt