Actually this question comes up a lot so this will be helpful to many.
The script will prompt you to select the columns which have a spec property. So you need to make sure the spec property is set before running this. It also creates a graph summarizing the in spec rates for each column split by grouping variables.
Names Default To Here( 1 );
dt = Current Data Table();
dlg = Column Dialog(
spec_cols = ColList( "Spec Columns", MinCol( 1 ), MaxCol( 1000 ) ),
group_cols = ColList( "Group Columns", MinCol( 1 ), MaxCol( 20 ) )
);
If( dlg["Button"] != 1,
Beep();
Throw();
);
col_list = dlg["spec_cols"];
group_list = dlg["group_cols"];
for (i=1, i <= nitems(col_list), i++,
col_name = col_list[i] << Get Name;
specproperty = col_list[i] << Get Property( "Spec limits" );
if( (contains(char(specproperty), "LSL") > 0) & (contains(char(specproperty), "USL") > 0),
Eval(Eval Expr(
dt << New Column( col_name || " In Spec", Numeric, "Continuous", Format( "Best", 12 ),
Formula(if((Expr(col_list[i]) > Expr(specproperty["LSL"])) & (Expr(col_list[i]) < Expr(specproperty["USL"])), 1, 0 )))
));
);
if( (contains(char(specproperty), "LSL") == 0) & (contains(char(specproperty), "USL") > 0),
Eval(Eval Expr(
dt << New Column( col_name || " In Spec", Numeric, "Continuous", Format( "Best", 12 ),
Formula(if(Expr(col_list[i]) < Expr(specproperty["USL"]), 1, 0 )))
));
);
if( (contains(char(specproperty), "LSL") > 0) & (contains(char(specproperty), "USL") == 0),
Eval(Eval Expr(
dt << New Column( col_name || " In Spec", Numeric, "Continuous", Format( "Best", 12 ),
Formula(if(Expr(col_list[i]) > Expr(specproperty["LSL"]), 1, 0 )))
));
);
);
cols = dt << Get Column Names();
inspec_cols = {};
for (i=1, i <= nitems(cols), i++,
if (Contains(cols[i], "In Spec"),
Insert Into(inspec_cols, cols[i])
);
);
dt << Group Columns("In Spec Cols", inspec_cols);
dt_inspec_stack = dt << Stack(
columns( Column Group( "In Spec Cols" ) ),
Source Label Column( "Spec Columns" ),
Stacked Data Column( "In Spec" ),
Drop All Other Columns( 1 ),
"Non-stacked columns"n( Keep( group_list ) ),
Output Table("Stack of In Spec Columns")
);
summary_group = {};
for (i=1, i <= nitems(group_list), i++,
col_name = group_list[i] << Get Name;
Insert Into(summary_group, col_name);
);
Insert Into(summary_group,"Spec Columns");
dt_inspec_summary = dt_inspec_stack << Summary(
Group( summary_group ),
Mean( :In Spec ),
Freq( "None" ),
Weight( "None" ),
output table name(
"Summary of In Spec Columns"
)
);
dt_inspec_summary << New Column("CI", Numeric, "Continuous", Format("Best",12),
Formula(Root( (:"Mean(In Spec)"n * (1 - :"Mean(In Spec)"n)) / :N Rows ) * 1.96)
);
dt_inspec_summary << Graph Builder(
Size( 1280, 720 ),
Show Control Panel( 0 ),
Variables(
X( :Spec Columns ),
Y( :"Mean(In Spec)"n ),
Group X( :Reactor ),
Interval( :CI )
),
Elements(
Points( X, Y, Legend( 5 ), Error Interval( "Custom Interval" ) ),
Line( X, Y, Legend( 6 ) )
),
SendToReport(
Dispatch( {}, "Mean(In Spec)", ScaleBox,
{Format( "Percent", 12, 0 ), Min( 0 ), Inc( 0.2 ), Minor Ticks( 1 ),
Label Row( {Show Major Grid( 1 ), Show Minor Grid( 1 )} )}
),
Dispatch( {}, "Graph Builder", FrameBox, {Reference Line Order( 3 )} ),
Dispatch( {}, "Graph Builder", FrameBox( 2 ), {Reference Line Order( 3 )} ),
Dispatch( {}, "Graph Builder", FrameBox( 3 ), {Reference Line Order( 3 )} )
)
);