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.
![txnelson_0-1674973963754.png txnelson_0-1674973963754.png](https://community.jmp.com/t5/image/serverpage/image-id/49580iE6B57B8CCE229175/image-size/medium?v=v2&px=400)
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.
![txnelson_1-1674974142812.png txnelson_1-1674974142812.png](https://community.jmp.com/t5/image/serverpage/image-id/49581i29367EBC4297CC9E/image-size/medium?v=v2&px=400)
I did this because the code allows you to specify more than one list in file2. So that if your file2 looked like this:
![txnelson_2-1674974400220.png txnelson_2-1674974400220.png](https://community.jmp.com/t5/image/serverpage/image-id/49582i61E60011988FF061/image-size/medium?v=v2&px=400)
It would give you the following results
![txnelson_3-1674974445450.png txnelson_3-1674974445450.png](https://community.jmp.com/t5/image/serverpage/image-id/49583iC8243F3D9027EDA4/image-dimensions/511x212?v=v2)
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