The code I previously provided, did exactly what you want, with one exception. Instead of providing the Max value, it provided the Sum of the columns specified. I have reworked the script, and changed from the Sum to the Max. I am also using your example data tables.
My code uses the name from column in file2, as the name to be used for the new column added in the main data table.
I did this because the code allows you to specify more than one list in file2. So that if your file2 looked like this:
It would give you the following results
Names Default To Here( 1 );
// Create the sample data tables
New Table( "Main",
Add Rows( 5 ),
New Column( "office1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 3, 2, 1, 4] )
),
New Column( "office2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [3, 2, 5, 0, 1] )
),
New Column( "office3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [0, 6, 3, 2, 2] )
),
New Column( "office4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [6, 4, 2, 3, 7] )
),
New Column( "office 5",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 3, 2, 1] )
)
);
New Table( "Config",
Add Rows( 3 ),
New Column( "Maxlist",
Character,
"Nominal",
Set Values( {"office1", "office2", "office4"} )
)
);
wait(5); // I put in a wait just so you can see the 2 tables
// The code below this line is the that does the calculations The code above this line would
// not normally be included
Names default to here(1);
// point to the large data table with lots of rows and columns
dt = data table("Main");
// If you are opening the table from a folder, this statement would be
// dt = open("the path to the table");
// point to the second data table that contains a list of columns to be summed
dtMax = data table("config");
// If you are opening the table from a folder, this statement would be
// dtMax = open("the path to the table");
// Just added a short pause so one can see the original tables before changing
// Create the new columns
For( i = 1, i <= N Cols( dtMax ), i++,
sumList = Column( dtMax, i ) << get values;
dt << New Column( Column( dtMax, i ) << get name );
Column( dt, N Cols( dt ) ) << set formula(
Eval( Parse( "max(" || Concat Items( sumList, "," ) || ")" ) )
);
);
Jim