The number of rows is processed after the rows have passed.
You add a variable to each row when they go through the step of the derived column, but at that time the variable is not updated (as it happens after all the rows have passed), so the value 0 is correct.
You can achieve this by using an asynchronous task in front of your derivative (but I'm not sure if this will work, it just appeared on my mind). Add a Sort or Aggregate step in front of your Derived and try again.
source share