The Value 2 results can easily replace the Value 1 results.
No you do not need to hard code the JSL for all of the columns. I have expanded my previous code to illistrate how to run this on as many columns as there are in the data table. I also made the assumptions that you would not want the original Value1 data changed for the Time=0 rows, but if that is not the case, then just remove the If() statement that is making that decision
Names Default To Here( 1 );
dt = Current Data Table();
// Create a subset with only the data where Time = 0
dt2 = dt << subset( Rows( dt << get rows where( :Time == 0 ) ), selected columns( 0 ) );
// Delete the Time column. In the join step below, it
// will write on top of the original Time column if
// it remains in the subsetted data table
dt2 << delete columns( "Time" );
// Create a list of the column names so all of them can be
// changed to a new name for the Join below. Eliminate
// the columns "id" and "Part" from the name change since
// they will be used in the column matching in the Join.
divisorColNames = dt2 << get column names( string );
For( i = N Items( divisorColNames ), i >= 1, i--,
If( divisorColNames[i] == "id" | divisorColNames[i] == "Part",
divisorColNames = Remove( divisorColNames, i, 1 )
)
);
// Rename all of the divisor columns by "adding divisor_"
// in front of each name
For( i = 1, i <= N Items( divisorColNames ), i++,
Column( dt2, divisorColNames[i] ) << set name(
"divisor_" || Char( Column( dt2, divisorColNames[i] ) << get name )
)
);
// Join the data tables. All of the matching id and part
// values will be joined to all rows with the same values
dtJoin = dt << Join(
With( dt2 ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :id = :id, :Part = :Part ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 )
);
// The dt2 data table is no longer needed so close it
Close( dt2, nosave );
// Loop through all of the columns and create the new values
// unless the Time value is 0
For( theCol = 1, theCol <= N Items( divisorColNames ), theCol++,
For( theRow = 1, theRow <= N Rows( dtJoin ), theRow++,
If( dtJoin:Time[theRow] != 0,
Column( dtJoin, divisorColNames[theCol] )[theRow] = (
Column( dtJoin, divisorColNames[theCol] )[theRow]
-Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]) /
Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]
)
)
);
// Delete all of the no longer needed divisor columns
For( i = 1, i <= N Items( divisorColNames ), i++,
dtJoin << delete columns( "divisor_" || divisorColNames[i] )
);
Jim