Hi guys, I have this table:
I am using For each row in datatable to go through it.
What I need to do is check if my current row is the last row in the table with “Fail” as value in the second column.
Is this possible? How can I do it?
Thank you!
Hi guys, I have this table:
I am using For each row in datatable to go through it.
What I need to do is check if my current row is the last row in the table with “Fail” as value in the second column.
Is this possible? How can I do it?
Thank you!
Hi
Can you just let the for each row finish and then update the datatable after?
If so, follow these steps:
Let your datatable variable be called: DT1
Step 1: Create a new Int32 variable called ‘row_Index’
Step 2: Add an If statement inside the For each Row.
With the following IF Condition:
currentRow(“Status”).ToString = “Fail”
Then Branch:
Capture the row index using an assign
Left: row_Index (Int32).
Right: DT1.Rows.IndexOf(row_Index)
Else Branch - leave blank.
Step 3: After the for each row you can refer return the number values accordingly like this:
Insert an assign:
Left: Last_Number (new String variable)
Right: DT1.Rows(row_Index)(“Number”).ToString
Or you can take a look here:
DT_Find_Last_Row_of_a_Value.xaml (7.4 KB)
Hopefully this helps,
Cheers
Steve
sound also that it can be done more direct without for each row, when the case is about
→ Read Range Workbook
Output-> dt
→ Use the below condition in If:
If
dt.Rows.Cast(Of DataRow)().LastOrDefault(Function(row) row("Status").ToString().Equals("Fail")) IsNot Nothing
Then
Assign-> lastFailRow= dt.Rows.Cast(Of DataRow)().Last(Function(row) row("Status").ToString().Equals("Fail"))
Log Message-> "Last row with 'Fail': Number=" +lastFailRow("Number").ToString()
End If
Hope it helps!!
Regards
Hey @Gines_Cirera
you can try:
lastFailIndex = dtData.AsEnumerable().Select(Function(row, index) New With { .row = row, .index = index }).Where(Function(x) x.row("Status").ToString.Equals("Fail")).Select(Function(x) x.index).LastOrDefault()
in for each activity you can use if condition:
dtData.Rows.IndexOf(CurrentRow) = lastFailIndex
If it will be true that means it is the last row.
please check this working workflow:
BlankProcess82.zip (3.3 KB)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.