Help with Data Tables

Hi, I would appreciate anyone’s help with this Data Table situation.

I have 4 Data Tables

Table 1 - Main Data
Table 2- Data 1.1
Table 3- Data 2.1

Table 4- OutPut (Table with mandatory preset headers, I will be using this table to turn into a csv for an email)

I need to compare the rows in Table 1 and 2 then store the equal values in the assigned rows in Table 4,

Then compare the rows in Table 1 and 3 then store the equal values in the other assigned rows in Table 4.

How can i complete this?

Hi @MichaelB2442

You can go with the LINQ Expressions. Do you want to compare whole row values or you want to compare a single column value .

Could you be more specific.

A single column value

Okay @MichaelB2442

→ Let’s say the datatable Variable names are DT1 is Table1, DT2 is Table2, DT3 is Table3 and Output_DT is Output table.
→ Use the assign activity and give the below expression,

- Assign ->  Output_dt = (From A In DT1.AsEnumerable
                          Join B In DT2.AsEnumerable
                          On (A("Column name of DT1").ToString) Equals (B("Column name of DT2").toString)
                          Select DT1.Clone.Rows.Add(A.ItemArray)
                                           ).CopyToDataTable()

→ Then use the another assign activity and use the below expression again,

- Assign -> Output_DT = (From X In DT1.AsEnumerable
                         Join Y In DT3.AsEnumerable
                         On (X("Column name of DT1").ToString) Equals (Y("Column name of DT3").toString)
                         Select Output_DT.Rows.Add(X.ItemArray)
                                   ).CopyToDataTable()

→ Then the compared result data is stored in the Output_DT, Use the write range workbook activity to write the Output_DT to the Excel.

Note: Change the Column names in the LINQ Expression.

Hope it helps!!

1 Like

Hie @MichaelB2442 use this linq query to compare the data in the excel sheets
(
From row In dtinput
From row2 In dtinput2
Where CInt(row(“No”)) = CInt(row2(“No”)) And row.item(“Name”).tostring = row2.item(“Name”).tostring
Select row
).copytodatatable
modify the column name with your column name or else for more column name
cheers Happy Automation

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.