A column formula can be used to create what you want
As Constant( dt = Current Data Table() );
currentType = :Type;
theInitialValue = :Value[(dt << get rows where( :Type == CurrentType & :Repetition == 1 ))[1]];
:Value - theInitialValue;
The method works, however, given a data table of 55,000+ the formula is not very efficient.
A more efficient method is to use a simple script to create a new table that contains just the initial values, and then merge the table back into the original table, where the matching will allow for the replication of the initial values to all of the matching records
names default to here(1);
dt=
New Table( "Example2",
Add Rows( 8 ),
New Column( "Type",
Character,
Set Values( {"A", "A", "A", "A", "B", "B", "B", "B"} )
),
New Column( "Repetition",
Numeric,
Set Values( [1, 2, 3, 4, 1, 2, 3, 4] )
),
New Column( "Value",
Numeric,
Set Values( [4, 10, 8, 7, 6, 9, 5, 10] )
)
);
// Create a table with the initial values
dt << select where(:Repetition == 1 );
initialDT = dt << subset( selected rows(1), columns({:Type,:Value}));
// Rename column Value to Initial Value
initialDT:Value << set name("Initial Value");
// Merge the values back to the original table
dt << Update(
With( initialDT ) ,
Match Columns( :Type = :Type )
);
// Create a column that contains the difference
dt << New Column( "Difference",
formula( :Value - :Initial Value )
);
Jim