Greetings,
While I have asked a couple Group By questions on here, I have a final one that is proving to be challenging.
@ppr has been a tremendous resource, and I am hoping he can chime in one last time to help me with this.
What I am trying to accomplish:
Group by:
(From d in dtData.AsEnumerable
Group d by k=d("Extended Price").toString.Trim into grp-Group
So i have that part figured out.
Now, I need:
- For each row, in each group
- Apply the following formula under row.field(“quantity”) - CInt(Math.Ceiling(“quantity”)/0.9)
- Then, after that formula has been applied (basically dividing the value under the row field “quantity” by .9 and then rounding the answer up to the nearest whole number (example: 104.78 rounded up to 105.00), apply the sum method.
So, for each row in each group, apply that division and then round up method, and then sum all those up, and save them to a datatable.
I know that the rest of the code is going to be somewhat like this:
For each row - ??
Let cs = CInt(Math.Ceiling("quantity")/0.9) - ??
Let cn = grp.Sum(Function (cs) CInt( "0" & cs("Quantity").toString)) - ??
Let ra = New Object(){k, cs, cn}
Select dtData2.Rows.Add(ra)).CopytoDataTable
I know I am close. This is the result ChatGPT gave me:
dtData.AsEnumerable()
GroupBy(Function(d) d("Extended Price").ToString().Trim())
Select(Function(grp)
New With {
k = grp.Key,
cs = grp.Sum(Function(rc)
CInt(Math.Ceiling(rc("quantity")/0.9))),
.CopytoDataTable
Thank you very much in advance (especially @ppr! )