Compare DataTable for each row

Hi All,

Need your help to find the solution for below scenario.

I ahve one data table name as “ItemDataTable” (Shown in below Image)


And another DataTable Name as “ReportDataTable” Shown in below image

And from both data table I need to Compare the for each value as primary column is “Item Value” of ItemDataTable and “LineItemIdentifier” of ReportDataTable.

Output should be like what ever field is matching it should show matching and not matching for not matched.

Thanks,
Keshav

@keshav - This can be done two ways… Using a For Each Row activity or through While Loops.

  1. Read both Excel documents to a Table through an Excel Application Scope and Read Range activities.
  2. Use a For Each Row Activity, call one of the DT created above when reading the Excel Sheet.
  3. Within the For Each Row Activity, add an If Statement. If DT = DT; Success

Update…

Try the below either of the below. The count will be the reference row for the DT_ReportDataTable.

or

you can use two for each row condition to iterate one by one and inside for each row you can use if conditon to compare the two primary column values in order to get the matched and unmatched data.

Thanks,
Mohanraj.S

Thank you @Jarzzz

I am able to print correct Output.(I.e. Matching and Not Matching).

But Now I need to print output with The Value of both the table. eg- Item Value 10 Matching Item Material AAA with Line Item Material AAA or Item Value 10 Not Matching Item Material AAA with Line Item Material BBB like this.

Could you please suggest the solution for this. I followed second method for solution.

Thanks,
Keshav

1 Like

@keshav

To output the values with a Matching or Not Matching remove the Comment Activty in the “Then” and “Else” areas of the If Condition. Replace them with the following Log conditions…

True Condition
Log Activity = DT_ItemDataTable.Rows(count).Item(0).ToString + " " + DT_ItemDataTable.Rows(count).Item(1).ToString + " IS equal to " + DT_reportDataTable.Rows(count).Item(0).ToString + " " + DT_ReportDataTable.Rows(count).Item(1).ToString

False Condition
DT_ItemDataTable.Rows(count).Item(0).ToString + " " + DT_ItemDataTable.Rows(count).Item(1).ToString + " IS NOT equal to " + DT_reportDataTable.Rows(count).Item(0).ToString + " " + DT_ReportDataTable.Rows(count).Item(1).ToString

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