How to synchronize 2 loops

Hi, I’m trying to compare each row in an Excel file with another row in a diffrent file. if the rows are the same (rowstring_1 =rowstring_2) it must add 1 to the integer “T_sum” else it must add 1 to “F_sum”
for this I created the workflow underneath.
Excel.xaml (16.0 KB)
both tables have 400 rows. as it is now it is checking each single row with all 400 rows of the other. this equals to 160000 operations. what I’m trying is to synchronize both loops so it checks the first row with the first, the second with the second, third with third etc. so it’s only 400 operations.

Use continue Activity inside foreach loop if row1 = row2

1 Like

Hi, that doesn’t solve my problem

Hi @B.D,

Please try these steps.

  • Read the first excel file a datatable, Let it be DT1.
  • Read the second excel file to a datatable, DT2
  • Declare a counter variable, let it be “i”.
  • Use a while loop with condition (DT1.Rows.Count= DT2.Rows.Count) And i< =(DT1.Rows.Count-1)
  • Inside the while loop body, use an IF activity with condition DT1.Rows(i)(0).ToString = DT2.Rows(i)(0).ToString. If you would like to check the other column values, use DT1.Rows(i)(0).ToString+DT1.Rows(i)(1).ToString+DT1.Rows(i)(2).ToString etc.
  • Calculate T_Sum and F_sum according to the condition.
  • Outside the IF activity, increment the value of i by 1.
    Hope this will meet your requirement. :slightly_smiling_face:
    Please have a look at this. ExcelSyncBD.zip (12.8 KB)

Regards,
Nimin

1 Like

Thamk you so much for your help

1 Like

what do I need to change in your method to compare a row with all of its columns ? I used String.join(“,”,itemArray) to combine them into a single string. where do I have to set the (i) in this ?
thanks again

Hi @B.D,

Sorry for delay in response. Please assign Row_String1 = String.Join(",", DT1.Rows(i)) and String2 = String.Join(",", DT2.Rows(i)) inside the while loop.

Regards,
Nimin

1 Like

Hi, sorry to bother you again…
I tried your solution and it worked after I added “.itemArray” to String.Join(“,”, DT1.Rows(i).itemArray). apparently it is necessary to function.
Now I modified the workflow so instead of only checking one specific file with another it iterates though a folder with Excel files and compares all of them to the specific file.
but when I let it run the message box displays the same result for every file but the first. at the beginning for the first file in the folder it says “rows with the identical content: 0, rows with diffrent content: 0”
for the rest of the files it displays “rows with the identical content: 334, rows with diffrent content: 67” which isn’t true.

any idea how to solve this ?
here the fileExcelSync2.xaml (13.5 KB)

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