Add this script to you data table and give it a spin
dt1=current data table();
//I want to get the max quantity by lot, so I'm adding a new column to change all the lots back to their non-decimal value.
dt1<< New Column("Lot Actual", formula(If( :Qty == Col Maximum( :Qty, Char( Round( Num( :Lot# ), 0 ) ) ),
:Lot#,
.
)));
//this next formula column excludes rows that aren't the max Qty by lot
dt1<< New Column( "Lot Values in One Formula",
Formula(
If( :Lot Actual == "",
Row State( row() ) = Excluded State( 1 );
Excluded( Row State( row() ) );
1;
)
)
);
dt1<<run formulas();
//once all the formulas for tagging the data are added, we can use Tabulate to get a subset of just the important rows.
//There are lots of other ways to do this, this just happened to be the method of the day
obj1=dt1 << Tabulate(
Add Table(
Column Table( Analysis Columns( :Qty ) ),
Row Table( Grouping Columns( :Lot# ) )
)
);
dt2=obj1 << Make Into Data Table;
column(dt2,2)<<set name("Lot Max");
//Finally here is the rolling sum of the last three lots
//there is moving average function we could have used, it would have looked simpler but more abstract
dt2<<new column("Rolling Sum of 3",formula(If( Row() == 1,
:Name( "Lot Max" ),
If( Row() == 2,
Lag( :Name( "Lot Max" ), 1 ) + :Name( "Lot Max" ),
:Name( "Lot Max" ) + Lag( :Name( "Lot Max" ), 1 )
+Lag( :Name( "Lot Max" ), 2 )
)
)));
//
//This part joins the values from the separate table back to the original table
dt1 << Update(
With( dt2 ),
Match Columns( :Lot# = :Lot# )
);
close(dt2, nosave);
obj1<<close window;
dt1<< Delete Columns("Lot Actual", "Lot Max", "Lot Values in One Formula");
///
//I feel like this step is cheating a little. This step just repeats the missing values down to the next non-missing
//row. Its some code I got from Brady Brady a ways back. Different iterations of come in handy from time to time.
dtnr=current data table();
dtcollist=dtnr<<Get Column Names;
dtMat = (dtnr << Get All Columns As Matrix);
selection={}; insert into (selection, column(4)); //these columns get acted on
For( i = 1, i <= N Items( selection ), i++,
colNum = Contains( dtColList, Name Expr( selection[i] ) );
vMat = dtMat[0, colNum];
mis = Loc( Is Missing( vMat ) );
If( N Row( mis ),
col = selection[i];
If( mis[1] == 1,
col[1] = col[(Loc( vMat ))[1]]
);
For( j = if(mis[1]==1, 2, 1), j <= N Row( mis ), j++,
col[mis[j]] = col[mis[j] - 1]
);
);
);
JMP Systems Engineer, Health and Life Sciences (Pharma)