Here is a little script that produces the below output
Names Default To Here( 1 );
dt = Current Data Table();
dtStack = dt << Stack(
columns( :Site1, :Site2 ),
Source Label Column( "Site" ),
Stacked Data Column( "Defect Count" ),
Output Table( "Stacked" )
);
dtStack << Sort(
By( :Date, :Site, :Defect Count ),
Order( Ascending, Ascending, Descending ),
Replace Table( 1 )
);
// New column: Column 5
dtStack << New Column( "Rank",
Numeric,
"Continuous",
Format( "Best", 12 ),
formula( Col Cumulative Sum( 1, :Date, :Site ) )
);
dtStack:Rank << delete formula;
dtStack << Select Where( :Rank > 3 );
dtStack << delete rows;
Jim