The formula section within a New Column is not parsed and evaluated as one might expect. I have found, that the best way to handle this, is to generate a literal string of the complete New Column phrase, exactly as you would want it if you manually typed it in, and then to execute that line. The code below does that
Names Default To Here( 1 );
dt2 = Current Data Table();
Xlist = "";
Ylist = "";
For( i = 1, i < N Cols( dt2 ), i++,
If(
Contains( column(dt2,i) << get name, "XXX" ) > 0, Xlist=Xlist || ":" || char(column(dt2,i) << get name) || ",",
Contains( column(dt2,i) << get name, "YYY" ) > 0, Ylist=Ylist || ":" || char(column(dt2,i) << get name) || ","
)
);
eval(parse("dt2 << New Column( \!"Xsum\!", Numeric, Continuous, Format( \!"Best\!", 12 ), Formula( Sum( "||Xlist ||") ) );"));
eval(parse("dt2 << New Column( \!"Ysum\!", Numeric, Continuous, Format( \!"Best\!", 12 ), Formula( Sum( "||Ylist ||") ) );"));
Jim