Darren,
I have created some sample data tables that I have attached to this reply.
Here is the script I developed. I am sure it will need to have some modifications to meet your exact requirements, but it works with my sample data. I tried to make my sample data as close to your data as necessary.
// Before running this script, open up the measurement and limits data tables.
// If you are using the two files I attached to the reply, the dtmeas = and
// dtlim = statements below are pointing to the correct data table. But if
// you use different data tables, you need to change the Data Table names
Names Default To Here( 1 );
dtmeas = Data Table( "Measurements Table" );
dtlim = Data Table( "Limits Table" );
// Split the data table based upon the Grade Code so each group is in a different
// column
dtsplitmeas = dtmeas << Split( Split By( :GRDBWT ), Split( :ACC Basis Weight ) );
// Get the column names from the split data table, which are really the different
// Grade Codes
cols = dtsplitmeas << get column names( string );
// Loop across the split data table and read the values for that column from the
// dtlim data table. Populate the Spec Limits and Control Limits
For( i = 1, i <= N Cols( dtsplitmeas ), i++,
limrow = Try( (dtlim << get rows where( dtlim:Gradecode == cols[i] ))[1], . );
If( Is Missing( limRow ) == 0,
specs = {LSL( . ), USL( . ), Target( . ), Show Limits( 1 )};
specs["LSL"] = dtlim:LOW[limrow];
specs["Target"] = dtlim:TARG[limrow];
specs["USL"] = dtlim:HIGH[limrow];
Column( dtsplitmeas, Char( cols[i] ) ) << set property( "spec limits", Eval( specs ) );
controllimits = {XBar( Avg( a ), LCL( b ), UCL( c ) )};
Substitute Into( controllimits, Expr( a ), dtlim:LWarn[limrow] );
Substitute Into( controllimits, Expr( c ), dtlim:uwarn[limrow] );
Substitute Into( controllimits, Expr( b ), dtlim:targ[limrow] );
Column( dtsplitmeas, Char( cols[i] ) ) << set property( "control limits", Eval( controllimits ) );
);
);
Once the new measurement table is produced, and the limits loaded into the column properties, the control charts can be produced. Please excuse my failure to center the actual sample data within the limits, but you can see that they are there.
Jim