Tmsn
(Tmsn)
January 31, 2024, 12:28pm
1
Hey
I am trying to add 2 rows in a dt.
First one should be empty.
Second one should have sums of some specific columns.
When trying to invoke a vb code I get the error message from the subject title.
Here is the code in text form:
in_dtEingang.Rows.Add()
Dim sumColumn6 As Double = 0
Dim sumColumn7 As Double = 0
Dim sumColumn10 As Double = 0
For Each row As DataRow In in_dtEingang.Rows
sumColumn6 += Convert.ToDouble(row(6))
sumColumn7 += Convert.ToDouble(row(7))
sumColumn10 += Convert.ToDouble(row(10))
Next
in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(6) = sumColumn6
in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(7) = sumColumn7
in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(10) = sumColumn10
Am I doing something wrong with the arguments?
Are the changes in the invoke code only changing the in_dtEingang or also effecting the dt_Eingang?
How would i get the edited dt out of the invoke code?
ppr
(Peter Preuss)
January 31, 2024, 12:39pm
2
We can avoid invoke code Black boxing by
Summing up col values with LINQ within Assign activity
This HowTo gives an introductory overview of the aggregation Operators: Min, Max, Sum, Average
Introduction
The aggregation operators are used to retrieve from a collection a particular result by setting the contained items into a relationship.
Overview
I – Input
P – Processing
O – Output
{2,12,-8,6,14,5}
get the lowest value
-8
{2,12,-8,6,14,5}
get the highest value
14
{2,12,-8,6,14,5}
sum up all values
31
{2,12,-8,6,14,5}
get the average of all values
5.17
Constraints
Perf…
Then assigning it to the last row by
Assign Activity
dtVar.AsEnumerable.Last()(ColNameOrIndex) = YourSum
1 Like
vrdabberu
(Varunraj)
January 31, 2024, 12:39pm
3
Hi @Tmsn
Can you share the sample input and expected output for that.
Regards
1 Like
ppr
(Peter Preuss)
January 31, 2024, 12:44pm
4
as a variation:
Assign Activity:
sum6 = dtVar.AsEnumerable().Sum(Function (x) Convert.ToDouble(x(6)))
… same for 7 and 10
Assign Activity:
drNew | Datarow = dtVar.NewRow
Assign Activity
drNew(6) = sum6
… same for 7 and 10
Add Row Activity adding drNew to dtVar
1 Like
Tmsn
(Tmsn)
January 31, 2024, 12:44pm
5
[Rang,Artikel,Whrg,Einht,Referenzartikelhauptgruppe,in %,Menge,Brutto,Rabatt Betrag,Rabatt %,Netto,Ø Preis
1,81120Boden-Bauschutt Z1.2 < 50% Bauschutt,EUR,t,40 Baurestmassen,0.6025966281675591,13478.7,211743.96,0,0,177936.04,13.2012760874565
]
This is one example input row
And the code should sum column 6,7 and 10 and add it
ppr
(Peter Preuss)
January 31, 2024, 12:46pm
6
Nicht ganz klar, can it be rephrased?
Tmsn
(Tmsn)
January 31, 2024, 12:47pm
7
This is the input/what’s in dt_eingang
Its only one datarow and not 10+ as in the real case.
But after multiple rows it should add one row and sum specific columns
system
(system)
Closed
February 3, 2024, 12:50pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.