Dealing with the last row of DataTable when using a loop

hello,

can someone help me with the issue:
when iterating through all rows of a DataTable using ‘For each row in DataTable’ and a ‘IF’ condition that checks:
if the current row value is equal to the next row value->go to process 1, otherwise, go to process 2.

It works well until the last row come along (that next row has no value and it out of the DataTable range)-> it returns an error that there is no line at position X (for example)

how can still use this condition and direct to process 2 when the last row comes?

Hey just create index variable for foreach row in it’s output property and check in “if condition” that if database.rows.count= index then execute process 2.

Note: Index will increase on every Iteration in foreach row activity automatically.

it doesn’t help,
the error occurs because my condition is if the current row(last row) equal to a row that doesn’t exists

i want to still be able to work with this condition but work around the missing row

Hi @Lior_Ben_Naim

Try to keep a setup like this and try
image

@Lior_Ben_Naim

Check below for your reference

Reference

Hope this may help you

Thanks

@Lior_Ben_Naim
we can achieve it compact without additional check if it is last row by:


grafik

output index varname is previdx

input:
grafik
Log:
grafik

find starter help here:
ForEach_CheckPrevWithNextRow.xaml (8.4 KB)