I want to fetch all rows that contains the number present in the list i.e. list1-> 900,971
After getting the datarows with given list. I want to group within that list by column Partner,Date,Pinta and only make a group of rows whose threshold is less than 100 and alos should be grouped in descending order.
after grouping the datatrows in descending order. I want to replace that particular group boat no. with highest weight row’s purchase other.
I know its bit confusing so I you can refer the output below.
for reference row no. 2 and 4 are grouped into one because according to descending order this are the first two row which is less than threshold value 100 and for that group 70.29 is highest value in both rows so its corresponding row purchase no is inputted in Boat no and similar goes for row 3 and 5, row 6 and 8, row 7 is grouped individual because its value when descending in row 5,6,7 comes last and when grouped together threshold is more than 100 so only row 6 and 8 is grouped and row 7 is grouped individual, row 9 is not grouped by anyone because its partner column and pinta and date doesnt match with anyone.
Total sum of a group of weight column should be less than or equal to 100.
2.order group by weight column since while making a group the highest weight row is preferred first.
the second datatatable is the output the output I should get when I perform the mentioned steps.
I am testing below query but it returns rows only when sum of whole group is less than 100 it doesnt split the group accordingly
(From d In dt1.AsEnumerable
Group d By k1= d(“Partner”).toString.Trim,k2 = d(“Date”).toString.Trim,k3 = d(“Pinta”).toString.Trim Into grp=Group
Let c = String.Join(“|”, grp.Select(Function (sd) sd(“sales”).toString).toArray)
Let ra = New Object(){c,k1,k2}
Where grp.Sum(Function(i) Convert.ToDouble(i.Field(Of Double)(“Weight”).ToString)) < 100
Select dtresult.Rows.Add(ra)).CopyToDataTable
(From d In dt1.AsEnumerable
Group d By k1= d(“Partner”).toString.Trim,k2 = d(“Date”).toString.Trim,k3 = d(“Pinta”).toString.Trim Into grp=Group
Select g=grp.toList).toList
And process the group and its memeber within the a nested for each
(outer loop = Groups, inner loop the group members)
Here you can realize the group member spliting merging in a more traceable way
Doing grouping
Split the groups on threshold or accepts a higher threshold when it is the first group member
creates the rows with concated values… etc