The issue with your current formula, is the variables "i".and "New Columns". What you are assuming is that the calculation will be evalueated to a final calculation, and then placed into the As Column() function. The issue is that what is placed into the formula is As Column( 13 + i + new columns ). So when the formula is executed, it does not have the values of "i" and "new columns" when you created the column, but it uses whatever the values are whenever it calculates or recalculates the formulas. And since "i" and "New Columns" is changing within your script, you have an issue. Now you could change the formula to do the calculation before defining the formula, and then substitute in the column number into the formula. However, the issue with this is that by using column numbers, if a column in the table is moved, or deleted, the column number in the formula will not be changed and therefore, the calculation will be wrong. I suggest that you instead, substitute into the formula, the actual column name. The below script illustrates the approach to do that.
Names Default To Here( 1 );
dt = Current Data Table();
sample = {0, 1, 2};
new columns = N Items( sample );
For( i = 1, i <= new columns, i++,
col = Num( sample[i] );
colNamesList = dt << Get Column Names;
Wait( 0 );
Eval(
Substitute(
Expr(
dt << New Column( sample[i] || " Days",
formula( __column__ - :Name( "0" ) )
)
),
Expr( __column__ ),
":Name(\!"" || colNamesList[13 + i + new columns] || "\!")"
)
);
);
Jim