replacing missing values with data from the row above AND add 1

Hi @Yannick_Jasper , see new workflow attached

For good measure I have added both a Java Snippet and a Column Expressions equivalent.

Java snippet code:

// Your custom variables:

// retain value of previous OrderPositionID
Integer prevOrderPositionID=0;

// Enter your code here:

if (c_OrderpositionID ==null)
{
	out_OrderpositionID = prevOrderPositionID;	
}
else
{
	out_OrderpositionID = c_OrderpositionID;
	
}

prevOrderPositionID= out_OrderpositionID + 1; // remember latest output + 1 for next row

Column Expressions code:

// prevOrderpositionID is value to be remembered in case it is needed for next row
// it is defined here but NOT initialised.
// For column expressions to "Remember" the value on next row, it MUST NOT BE INITIALISED here! 
var prevOrderpositionID

if (column("OrderpositionID")==null)
{
    outvalue = prevOrderpositionID == null?0:prevOrderpositionID

}
else
{
    outvalue = column("OrderpositionID")
}

// value to be remembered for next row (if missing)...
prevOrderpositionID=outvalue + 1

// value to be returned for current row...
outvalue

See these links for background on how these java snippet and column expressions work

Adding missing values based on previous row value - with contiguous missing values.knwf (71.3 KB)

3 Likes