How to look multiple columns

I am getting orderno and quantity values from another datatable. If quantity and orderno (another datatable) matches with above table need to write Result as “Completed”

What is the unique value here?? I could see duplicate order numbers. Is it coming from another table??

@balanirmalkumar.s
In which datatable you want to write it as completed ?? is it on the first datatable?

Hi @balanirmalkumar.s

Assuming this is how the 2 tables you said look like:

Table 1


Table 2

Here is the Assign statement with a LINQ:


(From row In dt_Table1.AsEnumerable()
              Let match = dt_Table2.AsEnumerable().
                          Any(Function(r2) r2("OrderNo").ToString = row("OrderNo").ToString AndAlso 
                                              r2("Quantity").ToString = row("Quantity").ToString)
              Select dt_Table1.Clone().LoadDataRow({
                  row("OrderNo"), 
                  row("Quantity"), 
                  If(match, "Completed", row("Results").ToString)
              }, False)).CopyToDataTable()

Result:

Is this the result you expected?
Do let me know if it does not work or if you need an explanation of the logic behind the code, I’ll gladly help.

If it solves your issue, do mark my answer as a solution to this thread.

Thank You,
Happy Automation. :star_struck:

1 Like

in both tables order no will get dublicate. So only we need to check both orderno and quantity.

i need to write in second datatable

Hi @balanirmalkumar.s

Is my solution not working?

Hi @balanirmalkumar.s

1. Assuming that the Second Table has a “Results” Column:

The Code:

(From row In dt_Table2.AsEnumerable()
              Let match = dt_Table1.AsEnumerable().
                          Any(Function(r2) r2("OrderNo").ToString = row("OrderNo").ToString AndAlso 
                                              r2("Quantity").ToString = row("Quantity").ToString)
              Select dt_Table2.Clone().LoadDataRow({
                  row("OrderNo"), 
                  row("Quantity"), 
                  If(match, "Completed", row("Results").ToString)
              }, False)).CopyToDataTable()

The Output:

2. Assuming that there is No Results Column in second Table:

The Code remains the same, Just include a Add Column Activity before the assign statement

The Output:

I hope this helps. If it solves your query do mark it as solution.
Thank You.
Happy Automation :star_struck:

Hi @V_Roboto_V ,

  1. In first for reach row i am using second data table. In second for each row i am using first data table.

Inside second for each row i need to implement this logic.

Hi @balanirmalkumar.s

Using 2 nested for loops, increases time complexity. The LINQ given previously would be a better alternative. But here is the solution for a nested for loop as requested:

The Condition inside IF:

CurrentRow2("OrderNo").ToString.Equals(CurrentRow1("OrderNo").ToString) AndAlso CurrentRow2("Quantity").ToString.Equals(CurrentRow1("Quantity").ToString)

The output:

I hope this helps.

Happy Automation :star_struck: