How to loop twice with remaining elements on the subloop

how can I loop through the same datatable twice , but for each initial row, I check all the remaining rows not the whole datatable from the first row.
image

So if I have:
A
B
C
D

I want to compare,
A with B, C, D
B with C, D
C with D

Thank you
H.Noka

** 1. Use a “For Each Row” activity to loop through each row in the DataTable “dt.”
2. Inside the first “For Each Row” activity, use another “For Each Row” activity to loop through the remaining rows in the DataTable “dt.”
3. To ensure that the second loop starts from the next row after the current row of the first loop, you can use the “Assign” activity to get the index of the current row in the first loop, and then use that index to set the starting point of the second loop.**

Thank you for your response,
I know how to do it logically speaking, I just dont know how to write the dt of the second loop so that is sliced from the index of the first loop until the end,

Lets have a look at the following LINQ which can be also decomposed to essential activities

(From i in Enumerable.Range(0, dtVar.Rows.Count)
Let row1 = dtVar.Rows(i)
From row2 in dtVar.AsEnumerable.Skip(i + 1)
// now we can check row1 wit all looping row2
…

1 Like

@hurmet.noka

  1. Add a “For Each Row” activity as the outer loop and set the DataTable property to “dt.”
  2. Inside the “For Each Row” activity, add an “Assign” activity to get the index of the current row.
  • Create a variable named “currentIndex” of type Int32.
  • In the “To” field of the “Assign” activity, enter dt.Rows.IndexOf(row).
  1. Add a “Filter Data Table” activity after the outer loop.
  • Set the DataTable property to “dt.”
  • In the Filter Wizard, click on “Add Condition.”
  • Set the ColumnName to the primary key or any unique identifier column of your DataTable.
  • Set the Operator to “>”
  • Set the Value to "'" + currentIndex.ToString + "'". (Note the single quotes around the index value since it’s a string comparison.)
  • Click “OK” to add the filter condition.
  1. Add a “For Each Row” activity as the inner loop and set the DataTable property to the output of the “Filter Data Table” activity.
  2. In the inner loop, you can now compare the current row from the outer loop with each row in the inner loop. Access the values using row("ColumnName").
1 Like

Hey @hurmet.noka

Refer below xaml
Main.xaml (14.4 KB)

Hope it helps you !
Regards

Would look like this:


grafik
irow = dtData.AsEnumerable.Skip(idx + 1).copyToDataTable

1 Like

Hey @hurmet.noka
I have sent you whole file, please try now
Iterate.zip (3.1 KB)

1 Like

secondFlight row is belonging to another Datatable (we used the CopyToDataTable)

but we can calculate the index by:
idx = outer loop index
idx2 = inner loop index

the just add both indexes + plus the offsets (second loops starts later with your if is first row…)

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