(From x In dt.AsEnumerable
Group x By a = x(“ID”).ToString.trim,c = x(“Country”).ToString.trim,d = x(“Code”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Value”).ToString)).ToString
Let ra = New Object(){a, b, c, d}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x(“Value”).Tostring).Equals(0)).CopyToDataTable
this is grops by ID,Code and country column you can change the column names as needed
and taken the sum of Value column can be replaced as well
final dt will contains ID,Country,Code and sum if you need more columns replicate like ‘Let b =…’ as many times as you need and include them in ‘Let ra = New Object(){a, b, c, d}’
Please find below with modifications for column 7 Check
(From x In dt.AsEnumerable
Group x By a = x(“ID”).ToString.trim,c = x(“Country”).ToString.trim,d = x(“Code”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Value”).ToString)).ToString
Let e = If({"EAZ","EANW"}.Any(function(x) String.Join(",",grp.Select(fucntion(x) x("Column7").ToString)).Contains(x),"EA","NA")
Let ra = New Object(){a, b, c, d, e}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x(“Value”).Tostring).Equals(0)).CopyToDataTable
(From x In dt.AsEnumerable
Group x By a = x(“ID”).ToString.trim,c = x(“Country”).ToString.trim,d = x(“Code”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Value”).ToString)).ToString
Let e = If({"EAZ","EANW","EANO"}.Any(function(x) String.Join(",",grp.Select(fucntion(x) x("Column7").ToString)).Contains(x),"EA",grp.Select(fucntion(x) x("Column7").ToString).FirstOrDefault)
Let ra = New Object(){a, b, c, d, e}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x(“Value”).Tostring).Equals(0)).CopyToDataTable
What this condition does is if after grouping in the column 7 if it has any of these “EAZ”,“EANW”,“EANO” then that row get ‘EA’ else that row gets first value which is present in that group of values from column7
(From x In dt.AsEnumerable
Group x By a = x(“Column6”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Column8”).ToString)).ToString
Let e = If({"EAZ","EANW","EANO"}.Any(function(x) String.Join(",",grp.Select(fucntion(x) x("Column7").ToString)).Contains(x),"EA",grp.Select(fucntion(x) x("Column7").ToString).FirstOrDefault)
Let ra = New Object(){a, b, e}
Select dt.Rows.Add(ra))).CopyToDataTable
This will have 3 columns 1 (the Groupdby column6) 2 (Column7 containign Conditions) and 3 (Sum containing the cum of Column8)
When you copy paste please replace the inverted comma
If you want to include the value of any other columns then add
‘Let f = grp.Select(fucntion(x) x(“Column2”).ToString).FirstOrDefault’
and also add ‘f’ in the line like this ‘Let ra = New Object(){a,b,e,f}’
This can be done for any column you need by changing the column name and corresponding assigned value
This is exactly with the columns as well… For the EA piece you have to replace the column values before this step. You can either use a for loop to do that or use a invoke code
This to be in invoke code
dt.AsEnumerable.ToList.ForEach(Sub(row)
If {"EAZ","EANW","EANO"}.Any(Function(x) row("Column 7").ToString.Contains(x)) Then
row("Column 7")="EA"
End If
End Sub
)
This one in Assign
(From x In dt.AsEnumerable
Group x By a = x("Column 6").ToString.trim,b = x("REGNO").ToString.trim,l = x("Column 7").ToString.trim Into grp = Group
Let c = grp.Sum(Function(p) CDBL(p("Column 8").ToString)).ToString
Let d = grp.Sum(Function(p) CDBL(p("Column 9").ToString)).ToString
Let e = grp.Sum(Function(p) CDBL(p("Column 10").ToString)).ToString
Let f = grp.Select(Function(p) p("Column 11").ToString).FirstOrDefault
Let i = grp.Select(Function(p) p("Column 3").ToString).FirstOrDefault
Let j = grp.Select(Function(p) p("Column 4").ToString).FirstOrDefault
Let k = grp.Select(Function(p) p("Column 5").ToString).FirstOrDefault
Let h = grp.Select(Function(p) p("Date").ToString).FirstOrDefault
Let ra = New Object(){h, i , j , k, l , a, b, c, d, e, f}
Select dt.Rows.Add(ra)).CopyToDataTable