Yes, that should work as long as the columns never are renamed.
This code illustrates the difference between the two approaches. The ugly string method hard codes the formula to a specific column. The second method looks for a column with a specific name (which could be useful)
// Example table
dt = New Table( "Test",
Add Rows( 4 ),
New Column( "Col1", Numeric, Set Values( [1, 2, 3, 4] ) )
);
// Add formula by parsed string
colNames = dt << get column names( string );
numCols = N Items( colNames );
For( i = 1, i <= numCols, i++,
colName = colNames[i];
col = New Column( "Cumulative " || colName, Numeric );
Eval(
Parse(
Eval Insert(
"col<< Set Formula(Summation(j = 1, row(), ^(ColName)^))"
)
)
);
);
// Add formula by substituting expression
For( i = 1, i <= numCols, i++,
colName = colNames[i];
newName = "Cumulative " || colName;
col = New Column( newName,
Numeric,
Continuous,
Formula(
Eval(
Substitute(
Expr(
Summation( j = 1, Row(), As Column( xxx )[j] )
),
Expr( xxx ), colName
)
)
)
);
);
Wait( 1 );
// Change column name and a value and look how formulas work
Column( 1 ) << set name( "New Name" );
Column( 1 )[1] = 100;
Wait( 2 );
// Add new column with same name as the original column.
dt << New Column( "Col1", numeric, values( [1, 1, 1, 1] ) );
dt << rerun formulas;