you will need to add all values from dt1 to dt3, but when in for each of dt2, you need to check if ID is already in dt3 before add… if you can share what you already have i can help the rest.
Hi
Hope these steps would help you resolve this
—let’s take like we have three different datatable named dt1, dt2, dt3
—and assuming that in dt3 we have Calum only in column ID
—now use a FOR EACH ROW loop and pass the variable dt3 as input and inside the loop use a Lookup datatable activity and mention as these in property panel
Input value = row(“ID”).ToString
Datatable = dt1
Lookup column name = “ID”
Target column name = “Amount”
Output result = str_output1
And add another lookup datatable activity and mention as these in property panel
Input value = row(“ID”).ToString
Datatable = dt2
Lookup column name = “ID”
Target column name = “Amount”
Output result = str_output2
Where str_output1, str_output2 is a variable of type string defined in the variable panel
And next to these two lookup datatable activity use a assign activity like this row(“Amount1”) = str_output1.ToString
And
Another assign activity like this row(“Amount2”) = str_output2.ToString
And a final assign activity row(“Total Amount”) = Convert.ToInt32(str_output1.ToString)+Convert.ToString(str_output2.ToString)
I have just finished building a Robot with a similar problem.
Assuming DT1 and DT2 are as you specified, I would use the Programming.DataTable.JoinDataTables activity to join DT1 and DT2 using a Join Type = FULL (aka Outer Join in SQL), Join on DT1.id = DT2.id and output DT3.
DT3 will have columns id, amount and amount_1 (assuming the amount column is named the same in both DT1 and DT2, the join activity automatically makes the second identical column name unique by adding _1).
Then use Programming.DataTable.AddColumn to add the “Total Amount” column to DT3.
If you want to rename the Amount and Amount_1 columns, you can do so by Invoking a little VB.Net code"
DT3.Columns(“Amount_1”).ColumnName = “My New Name” . (Or something close to that, I have not tested it).
And then finally a simple for each row activity setting Total = Amount + Amount_1. You will have to handle the possibility that amount or amount_1 can be nothing as they will not default to 0 when the join does not match id’s in both tables. Do an if test on amount_1 is nothing then amount_1 = 0 before the addition assignment.