I need to compare several columns - subtract rows - and delete those rows that return zero and keep remaining.
The most rows are duplicates, but fx. ID 30 is not.
I have tried with this linq query, but the result is not quite, what I need. The ID 30 does not appear at all, due to group by!
(From x In dttemp Group x By a = x(“ID”).ToString.trim Into grp = Group Select
dttemp.Rows.Add({a,grp.sum(Function(k) CInt(k(“Value”).Tostring))})).CopyToDataTable
(From x In dt.AsEnumerable
Group x By a = x("ID").ToString.trim Into grp = Group
Let b = grp.Select(Function(x) CInt(x("Value").ToString)).
Take(CInt(grp.Select(Function(x) CInt(x("Value").ToString)).Count/2)).Sum(Function(x) CInt(x))
Let ra = New Object(){a, b}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x("Value").Tostring).Equals(0)).CopyToDataTable
You need 20 to be repeated twice? .where as others only once? Why is that?
And are you filtering the data before this? can you check your datatable if it has all rows before performing this step
and please try this
(From x In dt.AsEnumerable
Group x By a = x("ID").ToString.trim Into grp = Group
Let b = String.Join("||",grp.Where(Function(x) Not x("Value").ToString.Contains("||")).
Select(Function(x) x("Value").ToString)).Split("||",StringSplitOptions.None).Take(CInt(String.Join("||",grp.Where(Function(x) Not x("Value").ToString.Contains("||")).
Select(Function(x) x("Value").ToString)).Split("||",StringSplitOptions.None).Count-1)).Sum(Function(x) CInt(x.ToString))
Let ra = New Object(){a, b}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x("Value").Tostring).Equals(0)).CopyToDataTable
Compiler error(s) encountered processing expression “(From x In dt.AsEnumerable Group x By a = x(“ID”).ToString.trim Into grp = Group Let b = String.Join(”||“,grp.Where(Function(x) Not x(“Value”).ToString.Contains(”||“)).Select(Function(x) x(“Value”).ToString)).Split(”||“,StringSplitOptions.None).Take(CInt(String.Join(”||“,grp.Where(Function(x) Not x(“Value”).ToString.Contains(”||“)).Select(Function(x) x(“Value”).ToString)).Split(”||“,StringSplitOptions.None).Count-1)).Sum(Function(x) CInt(x.ToString))Let ra = New Object(){a, b}Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x(“Value”).Tostring).Equals(0)).CopyToDataTable”.
Overload failed because there is no available ‘Split’ that can be called with these arguments:
‘Public Function Split(separator() As String, options As System.StringSplitOptions) As String()’: A value of type ‘String’ cannot be converted to ‘1-dimensional array of String’.
I guess you are using windows-legacy, so just include curly braces as below(in split string). Below code should be compiled properly
(From x In dt.AsEnumerable
Group x By a = x("ID").ToString.trim Into grp = Group
Let b = String.Join("||",grp.Where(Function(x) Not x("Value").ToString.Contains("||")).
Select(Function(x) x("Value").ToString)).Split({"||"},StringSplitOptions.None).Take(CInt(String.Join("||",grp.Where(Function(x) Not x("Value").ToString.Contains("||")).
Select(Function(x) x("Value").ToString)).Split({"||"},StringSplitOptions.None).Count-1)).Sum(Function(x) CInt(x.ToString))
Let ra = New Object(){a, b}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x("Value").Tostring).Equals(0)).CopyToDataTable
I ran the bot and it did append the required output.
can you please check if you are checking the right file. I did not change anything in your xaml Except the “Path to Excel” to “text.xlsx”
I even ran with this and its working can you check
(From x In dt.AsEnumerable
Group x By a = x("ID").ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x("Value").ToString)).ToString
Let ra = New Object(){a, b}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x("Value").Tostring).Equals(0)).CopyToDataTable
Unfortunately, I have not solved the problem.
I actually have several rows in the Excel file and that is why I fx. needed ID 20 to stand separate.
Whether Spain or France comes out, it does not matter. It is important to include the columns country and code in the result.
I have tried with this query but I get this error:
(From x In dt.AsEnumerable
Group x By a = x(“ID”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Value”).ToString)).ToString
Let c = grp.Select(Function (x) x(“Country”).toString.Trim).ToString
Let d = grp.Select(Function (x) x(“Code”).toString.Trim).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
If you want to group by those columns use like this
(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
else you want to only group on ID then use this
(From x In dt.AsEnumerable
Group x By a = x(“ID”).ToString.trim Into grp = Group
Let b = grp.Sum(Function(x) CInt(x(“Value”).ToString)).ToString
Let c = grp.Select(Function (x) x(“Country”).toString.Trim).FirstOrDefault
Let d = grp.Select(Function (x) x(“Code”).toString.Trim).FirstOrDefault
Let ra = New Object(){a, b, c, d}
Select dt.Rows.Add(ra)).Where(Function(x) Not CInt(x(“Value”).Tostring).Equals(0)).CopyToDataTable