Java Snippet - Next Row Value

Hi,

I’m trying to figure out how to bring back the ‘Order_id’ value of the next row into the current row. I found a workflow example here that shows how to bring back the ‘Order_id’ value of the previous row into the current row (as seen in the below picture), though I’m unable to figure out how to modify this to bring back the ‘next’ row. Any thoughts on how to do this in a Java Snippet Node?

Below is what i have so far. The first two columns are the data, and the last column is from the Java snippet
A

The below highlighted column (filled this in manually for example) are the values i’m looking to bring back via java.
C

Hi @John-k

My solution would be to sort the table descending then execute the lag column and finally sort your table ascending again.
java_snippet_next_row_valuel
gr. Hans

4 Likes

Hi there,

additionally to simulate Lag Column node with negative value one can use Moving Aggregation node. Here is example:

Br,
Ivan

3 Likes

Thank You @HansS and @ipazin, both your solutions work. Would a solution be possible in the Java snippet, or would the Lag and Moving Aggregation nodes be the only way to accomplish this?

2 Likes

Hi there,

I’m sure it can be done in Java Snippet node but not my field so can’t help you there. Maybe @quaeler can help you with it.

Br,
Ivan

snippet previous row.knwf (6.3 KB)

1 Like

Thanks @quaeler - this works good. Is there a way to reverse the logic so it brings back the next row instead of the previous row?

No there isn’t. (Rows are consumed in a specific order; the reason we can reference the last row is because we’ve already had it given to the node (and so the reason we cannot reference the next row is because we have not been given it yet.))

3 Likes

Thank You for explaining this @quaeler - that makes sense. Much appreciated.

3 Likes

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