1,0 Change Indicator Column When Column Changes

Hello Fellow Knimers,

Hope all is well. I am stumped on a doozy I can’t figure out and I’ve been unable to find anything on the forum. Here’s my issue…

I have a table like this…

table 1

I want to add a column to the immediate right called “Change Indicator” which is populated with “1” when Student Status changes from preceding Date, by Name. So the result would look like this…

table 2

Note it’s only populated with “1” when Student Status by Name changes from preceding Date, otherwise it is “0”.

I hope I’m explaining this clearly.

Any and all assistance or direction greatly appreciated.

Thanks!

Chris

Hi @chrisgranelli

I can think of two options to go with depending if you like code or less-code :wink:

The less-code option would go via a Group Loop:

Here the Name column is the one that makes the group. Within the group, you can deploy a Lag Column node to retrieve the value of previous row.

With a Rule Engine you can determine if the change indicator should be applied or not:

NOT ($Student Status$ = $Student Status(-1)$) AND NOT MISSING $Student Status(-1)$ => 1
TRUE => 0

The code way only requires one node. The Column Expression has an access feature where you can also retrieve the value of a column on a particular offset.

You can evaluate this via:

if (column("Name").equals(column("Name",-1)) == true && column("Student Status").equals(column("Student Status",-1)) == false) {
   "1"
} else {
    "0"
}

This evaluates if the Name of the current row is equal to the Name of the previous row and if the Student Status of the current row is equal to the Student Status of the previous row.

Make sure that the multi-row access is enabled under the Advanced tab.

See WF:
1,0 Change Indicator Column When Column Changes.knwf (35.9 KB)

Hope this provides some inspiration!

5 Likes

Thanks so much ArjenEX!!! I’ll try now.

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