Here are couple of ways to do this, using Loc() and Eval(Eval Expr()) (a bit similar as here: Re: How to calculate relativ values based on a position of a base value? .
Names Default To Here(1);
dt = New Table("Example_USL_LSL",
Add Rows(10),
Compress File When Saved(1),
New Column("Sample",
Character(1),
"Nominal",
Set Values({"A", "A", "A", "A", "A", "B", "B", "B", "B", "B"})
),
New Column("Day",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([1, 2, 3, 5, 10, 1, 2, 3, 5, 10])
),
New Column("Data",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([10, 12, 9, 7, 5, 160, 158, 162, 67, 26]),
Set Display Width(46)
)
);
/*a = Loc(:Sample << get as matrix, :Sample);
b = Loc(:Day[a], 1)[1];
c = a[b];
:Data[c]*1.2; //0.8 for lsl
*/
dt << New Column("LSL", Numeric, Continuous, Formula(
If(Row() == 1,
dayOnes = Loc(:Day << Get as Matrix,1);
);
dayOneForSample = dayOnes[Loc(:Sample[dayOnes], :Sample)][1]; //current samples day 1 row number
:Data[dayOneForSample]*0.8;
)
);
dt << New Column("USL", Numeric, Continuous, Formula(
If(Row() == 1,
dayOnes = Loc(:Day << Get as Matrix,1);
);
dayOneForSample = dayOnes[Loc(:Sample[dayOnes], :Sample)][1]; //current samples day 1 row number
:Data[dayOneForSample]*1.2;
)
);
dt << New Column("LSL_eval", Numeric,"Continuous",Format("Best", 12), Formula(
Name Expr(
Eval(
Eval Expr(
:Data[(:Sample << get data table) << get rows where(
:Day == 1 & :Sample == Expr(:Sample[Row()])
)] * 0.8
)
)
)
));
dt << New Column("USL_eval", Numeric,"Continuous",Format("Best", 12), Formula(
Name Expr(
Eval(
Eval Expr(
:Data[(:Sample << get data table) << get rows where(
:Day == 1 & :Sample == Expr(:Sample[Row()])
)] * 1.2
)
)
)
));
If you were to use Loc() solution I would strongly suggest checking out it on smaller parts to understand what is going on.
-Jarmo