Hi @edwar_forero , although I can’t see your input data, I’m assuming that it is something like:
year | tiempo_entre_avieras |
---|---|
2013 | 365 |
2014 | 365 |
2015 | 365 |
Unfortunately the column expressions node only “remembers” the input values for previous rows within the defined window, but does not remember the output values. Therefore, it will add the 365 in 2015 to the input value of 365 in 2014, rather than the cumulative output value, thereby resulting in 730. I’m not aware of a workaround within the Column expressions nodes, and you would need to do something outside of column expressions including such nodes as Moving Aggregation to perform cumulative operations.
To my mind that all becomes a bit cumbersome, which is why for any such problem I turn to Java Snippets, and is one of the primary reasons I almost never used Column Expressions.
Java snippets are (arguably) marginally more complicated to write than Column Expressions, but the upside is you get proper compilation errors, and faster performance.
For the workflow I’ve attached below, I’ve had to create the data so it is slightly different to your numbers. I don’t know what the basis of your calculations were, and the workflow you uploaded doesn’t contain the base data in a form I could make work.
Anyway, assuming my understanding is correct, I think the following java snippet achieves what you are trying to do:
// Your custom variables:
int cumulTimeBetweenFailures=0; // keeps track of the cumulative time
int lastTimeBetweenFailure = 0; // stores value of failure time from last row
// Enter your code here:
if(lastTimeBetweenFailure >=365 && c_Timebetweenfailures < 365 )
{
cumulTimeBetweenFailures = c_Timebetweenfailures;
}
else if(lastTimeBetweenFailure < 365 && c_Timebetweenfailures >= 365)
{
cumulTimeBetweenFailures = c_Timebetweenfailures;
}
else
{
cumulTimeBetweenFailures += c_Timebetweenfailures;
}
lastTimeBetweenFailure=c_Timebetweenfailures; // store value from current row for checking next time
out_calctimebetweenfailures = cumulTimeBetweenFailures; // cumulative value to be returned for
cumulative failures-java snippet.knwf (16.7 KB)
For further info on how it works, see Java snippets have long memories!...