Previous row item in dataTable

Hi, I’m working on a project where I have to use data table and compare a particular column value of current row item with the previous row’s column value.

i know how to get the current previous index of datatable as(starts from index 2)

currentIndex = dt.Rows.indexof(row)+2

previousIndex = currentIndex - 1

I get exactly previous index of row, but what i need is i want corresponding value of previous row,
i tried like this,

dt.Rows(previousIndex)(“columnname”).Tostring

but it is fehcing next row value instead of previous row value.i need to get previous row value of datatable in for each activity.

Regards
raghu

2 Likes

Hi @rag
Welcome to uipath community
Great

  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
    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 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…thats why

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

2 Likes

Thanks palaniyappan, i will try , thank you so much

1 Like

Did that work @rag
Cheers

1 Like

Thanks bro its working
Reagards
rag

1 Like

Thats great,
Kindly make a solution with the right comment that could help others well
@rag

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