Hello @Jackie_ ,
I expect something like this to work for what you want. The syntax is probably incorrect, but the idea is on the right path. I believe using the associative arrays is the easiest path, since it automatically sorts entries in ascending / alphabetical order inherently.
Note that I've left group_tests_cols
empty. I see you've grouped them in "Tests", so you probably have a list, or a method for retrieving all of the column names to create a list.
Names default to here(1);
dt = current data table();
group_tests_cols = { };
// automatically sorts key data in ascending / alphabetical order
aa_tests_cols = Associative Array();
// Puts all of the test numbers as the keys in the AA
for( a = 1, a <= N Items( group_tests_cols ), a++,
test_number = column( dt, group_tests_cols[a] ) << Get Property( "Formula" );
eval( eval expr( aa_tests_cols[ expr( test_number ) ] ) ) = group_tests_cols[a];
);
aa_keys = aa_tests_cols << Get keys;
// Moves columns in the order of the keys
for( b = 1, b <= N Items( aa_keys ), b++,
col_name = aa_tests_cols[ aa_keys[b] ]; // uses index of the key to retrieve the actual value of the key, to get the col name
eval( eval expr( expr( column( dt, col_name ) ) << Move Selected Columns( expr( { as column( col_name ) } ), after( :name ) ) ) );
);
Learning every day!