Get previous row

In for loop I am getting excel data row by row.Now I also want in current row which I am getting row one by one in this I want previous record of specific column.As mentioned in attachment.
eg In excel sheet as mention in attachment.In 1st row and last column value is 977.535
Now loop goes to second record then I want 977.535 in second record I want previous row last column.
Every time I want with current row previous row last column.

So you can access in a for each loop - the last thing you can do at end of the loop is assign the current row to a datarow variable.
For Each row in DT
//Do Something
i.e. Assign - PreviousRow = row

1 Like

Did not understand

Hi @Aditya10989

Try this

  1. to get the current row i hope you are using for each row loop with datatable as input and getting the row index, but i would like to make a small suggestion with the way we get the currentindex, a integer variable
    it should be like this buddy
    currentindex = dt.Rows.IndexOf(row)
    actually this gives the index of the current row which is getting iterated from the for each row loop in dt, the table that you pass
    if you get like this
    currentindex = dt.Rows.IndexOf(row) + 2
    it adds up the row index with plus 2 from the current
    say for example we are in row 1 now, we want the row 1 and row 0, the previous one
    if we do with what mentioned by you buddy see,
    currentindex = dt.Rows.indexof(row)+2
    currentindex = 1 + 2
    currentindex = 3

then with previous formula you have
previousindex = currenindex -1
previousindex = 3 - 1
previousindex = 2 ,we are getting next row buddy…thats why

so use
currentindex = dt.Rows.IndexOf(row)
thats all buddy you were almost done buddy
Hope this would help and kindly try this and let know buddy

Ashwin S

So read your excel spreadsheet into datatable - using read range activity.

Then inside a For Each row activity -
// Complete process
use an assign activity with PreviousRow on the left (data type - datarow) = row (current datarow)
End of For Each - Go to Next Row

Then in the next loop - PreviousRow will be a datarow with the previous rows data which you can access like PreviousRow.Item(“ColumnA”).ToString etc.

Thanks for reply can we do like this as mention in attachment.
here i initialize by zero then increment by one column name always same

as you mentioned like this I got value 2.Now what I need to do…?