Ho ricevuto il formula di cui voglio discutere quasi 3 anni fa da @txnelson , da allora non l'ho mai lasciato andare e ci ho pensato molte volte prima d'ora, arrivando lentamente un po' più seriamente alle prese con lo scripting. Nel frattempo, la formula mi ha salvato molto di tempo.
Nell'esempio seguente, la stessa formula viene aggiunta 3 volte, ogni volta con una piccola variazione. Il problema di cui voglio discutere sono i diversi messaggi di errore generati durante la copia e l'esecuzione dello script della tabella, comprese le colonne formula appena aggiunte.
Names Default To Here( 1 );
// first, we need an example table
dt = New Table( "ExampleTable",
Add Rows( 24 ),
New Column( "BatchId",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D",
"D", "E", "E", "E", "F", "F", "F", "G", "G", "G"}
)
),
New Column( "StorageCondition",
Character,
"Nominal",
Set Values(
{"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "5°C", "5°C", "5°C",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH", "25°C/60%RH",
"25°C/60%RH", "25°C/60%RH", "25°C/60%RH"}
)
),
New Column( "Time",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
)
),
New Column( "QcParameter",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[0.2, 0.3, 0.4, 0.2, 0.21, 0.22, 0.3, 0.9, 1.2, ., 0.2, 0.4, 0.1, ., 0.1,
0, 0, 0, 0.1, 0, 0, 0, 0.1, 0]
)
)
);
// adding formula column via approach nr. 1<BR />// this adds the formula alright, but when copying and executing the resulting table script will leave the formula column empty<BR />// no need to discuss this, because this obviously missing the 'eval(eval expr(expr()))' wrapping (see screenshot below)
dt << New Column( "QcParameter [% rel.]_1",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = dt << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Row = theRows[1];
d0Time = :QcParameter[d0Row];
(100 * :QcParameter / d0Time);
)
);
// adding formula column via approach nr. 2<BR />// this will fill the formula column as desired when copying and running the table script with the added formula columns<BR />// but it will also throw an error message when new rows are added to the table then (see screenshot below)
Eval(
Eval Expr(
dt << New Column( "QcParameter [% rel.]_2",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = Expr( dt ) << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Row = theRows[1]; // removed from approach nr. 3
d0Time = :QcParameter[d0Row];
(100 * :QcParameter / d0Time);
)
)
)
);
// adding formula column via approach nr. 3
// this will fill the formula column as desired when copying and running the table script with the added formula columns<BR />// and it will NOT throw an error message when new rows are added to the table then (see screenshot below)
Eval(
Eval Expr(
dt << New Column( "QcParameter [% rel.]_3",
numeric,
formula(
curBatch = :BatchId;
curCondition = :StorageCondition;
theRows = Expr( dt ) << get rows where(
:BatchId == curBatch & :StorageCondition == curCondition & :Time == 0
);
d0Time = :QcParameter[theRows];
(100 * :QcParameter) / d0Time;
)
)
)
);
Screenshot del messaggio di errore per la colonna formula "QcParameter [%r rel.]_1]" quando si esegue nuovamente lo script di tabella con colonne formula aggiuntive:

Screenshot del messaggio di errore per la colonna formula "QcParameter [%r rel.]_2]" quando si esegue nuovamente lo script di tabella con colonne formula aggiuntive:

Screenshot del messaggio di errore per la colonna formula "QcParameter [%r rel.]_3]" quando si esegue nuovamente lo script di tabella con colonne formula aggiuntive:

Il motivo per cui sto ponendo questa lunga domanda è che presumo ci deve essere qualche motivo per cui la variabile "d0Row" viene utilizzata nell'approccio n. 2, no?Per l'avvicinamento n. 3 Ho semplicemente eliminato questa variabile (vedi screenshot sotto) e di conseguenza la formula si comporta "molto più bene", ovvero non viene visualizzato alcun messaggio di errore quando nuove righe vengono aggiunte ad hoc puntando e facendo clic sulla tabella dati.

La mia domanda è quindi se sto facendo qualcosa di sbagliato eliminando la variabile "d0Row". Nella vita reale sto lavorando con tabelle di dati più grandi e non sarò in grado di controllare l'accuratezza di ogni riga individualmente.