Below are 3 methods for doing what you want.
Names Default To Here( 1 );
dt = Data Table( "Bluegalaxy" );
// Method 1
dt << New Column( "% Change 1",
Format( "Percent", 9, 2 ),
set each value(
currDevice = :Device Number;
zeroCurrent = :Current[((dt << get rows where(
:Device Number == currDevice & :Stress Duration == 0
))[1])];
value = (:Current - zeroCurrent) / zeroCurrent;
)
);
// Method 2
// Sort the table in assending Device Number/Stress Duration
dt << sort(
By( :Device Number, Stress Duration ),
order( Ascending, Assending ),
Replace Table( 0 )
);
dt << New Column( "% Change 2",
Format( "Percent", 9, 2 ),
set each value(
If( :Stress Duration == 0,
zeroCurrent = :Current
);
(:Current - zeroCurrent) / zeroCurrent;
)
);
// Sort the table back to the original order
dt << sort(
By( :Stress Duration, Device Number ),
order( Ascending, Assending ),
Replace Table( 0 )
);
// Method 3
// Create a data table with only the 0 Stress Duration values
dt << Select Where( :Stress Duration == 0 );
dtZero = dt << subset( selected rows( 1 ), columns( :device Number, :current ) );
dtZero:current << set name( "zeroCurrent" );
dt << Update( With( dtZero ), Match Columns( :Device Number = :Device Number ) );
dt << New Column( "% Change 3",
Format( "Percent", 9, 2 ),
set each value( (:Current - :zeroCurrent) / :zeroCurrent )
);
// Clean up
dt << delete columns( zeroCurrent );
Close( dtZero, nosave );
dt << clear select;
All of these methods can be created in an interactive mode.
Note: I am using "Set Each Value" in the specification of the new columns. This can be swapped out for "Formula". The Formula specification allows for any new records to have the formula applied when they are added, or changed. In the case you have presented, I am assuming that you will want the values created only once, when the new column is created.
Jim