One way to dynamically build expressions from strings. In comparision to expressions, I think strings are more easy to manipulate.
Here an example. It "must" be a simpler way but it works.
Clear Globals();
//Make example table
dt = New Table( "test",
Add Rows( 3 ),
New Column( "A", Numeric, Continuous, Format( "Best", 1 ), Set Values( [0, 1, 1] ) ),
New Column( "B", Numeric, Continuous, Format( "Best", 12 ), Set Values( [0, 2, 2] ) ),
New Column( "C", Numeric, Continuous, Format( "Best", 12 ), Set Values( [0, 3, 3] ) ),
New Column( "D", Numeric, Continuous, Format( "Best", 12 ), Set Values( [4, 0, 4] ) ),
New Column( "E", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 0, 5] ) ),
New Column( "F", Numeric, Continuous, Format( "Best", 12 ), Set Values( [6, 0, 6] ) )
);
//define the criteria array
Cols = Associative Array();
Cols["A1"] = {A, B, C};
Cols["A2"] = {D, E, F};
Cols["abc"] = {"Total1", "Total2"};
//Make substrings iteratively
s1 = "Expr(Cols[\!"A1\!"][1])";
For( i = 2, i <= N Items( Cols["A1"] ), i++,
s1 = s1 || " + " || Substitute( "Expr(Cols[\!"A1\!"][_i_])", Expr( _i_ ), Char( Eval( i ) ) )
);
s2 = "Expr(Cols[\!"A2\!"][1])";
For( i = 2, i <= N Items( Cols["A2"] ), i++,
s2 = s2 || " + " || Substitute( "Expr(Cols[\!"A2\!"][_i_])", Expr( _i_ ), Char( Eval( i ) ) )
);
// Strings representing expressions, substitute _s_ for substrings
newcol_s1 = "dt << New Column( Cols[\!"abc\!"][1], Numeric, Continuous, Formula( If( _s_ > 0, 1, 0 ) ) )";
Substitute Into( newcol_s1, Expr( _s_ ), s1 );
newcol_s2 = "dt << New Column( Cols[\!"abc\!"][2], Numeric, Continuous, Formula( If( _s_ > 0, 1, 0 ) ) )";
Substitute Into( newcol_s2, Expr( _s_ ), s2 );
//Parse complete strings
e1 = Parse( newcol_s1 );
e2 = Parse( newcol_s2 );
//Make new columns by evaluating the substring expr and then the complete expressions.
Eval( Eval Expr( e1 ) );
Eval( Eval Expr( e2 ) );