Skip to main content

I’m working with two data tables in Automation Anywhere and I need to loop through both tables simultaneously while comparing values (specifically temperatures). The challenge I’m facing is incrementing a counter once for both tables as I go through each row.

Here’s what I want to achieve:

  • I have two tables: WeatherOld and WeatherCurrent.
  • I need to loop through both tables at the same time, comparing values from corresponding rows in both tables (e.g., comparing temperatures from the same city).
  • I want to increment a counter once for both tables after processing each set of corresponding rows.

How can I structure my loops and ensure the counter increments correctly for both tables at once?

Any suggestions or guidance would be much appreciated!

Thanks in advance!

Hi @ShammaH,

you can use nested loops. Here’s a step-by-step guide:

Create Data Tables: Ensure you have two data tables, let’s call them Table1 and Table2.

Initialize Counters: Create two variables, Counter1 and Counter2, and initialize them to 0.


Outer Loop for Table1:
Use the “Loop” action and select “For each row in DataTable”.
Choose Table1 as the data table.

Increment Counter1:
Inside the loop, use the “Variable Operation” action to increment Counter1 by 1.

Inner Loop for Table2:
Within the outer loop, add another “Loop” action for Table2.
This will loop through each row of Table2 for every row in Table1.

Increment Counter2:
Inside the inner loop, use the “Variable Operation” action to increment Counter2 by 1


You can also use numeric indices for the tables. The UI isn't very clear about it, but you can use number variables in both rows and columns of the data table. 


Hi  @Tamil Arasu10,

Thank you for your suggestions! I’ve tried the approach you mentioned with nested loops and initializing two counters (Counter1 and Counter2), but the issue I’m running into is that the outer loop counter (Counter1) isn’t incrementing as expected.

I’m not sure where I’m going wrong. The inner loop counter (Counter2) increments properly as it loops through Table2, but Counter1 stays the same after each iteration of the outer loop (looping through Table1).

Could you help me troubleshoot why Counter1 isn’t incrementing in the outer loop?

 

Thanks again for your help!

 


Delete


Nested loops will work like this:

1 - 1

1 - 2

1 - 3

2 - 1

2 - 2

2 - 3

3 - 1

3 - 2

3 - 3

If you need the counters synched, you will have have to work with your own counters rather than using the counters from the loop action.


Reply