he recibido el fórmula que quiero discutir hace casi 3 años desde @txnelson , nunca lo solté desde entonces y lo pensé muchas veces hasta ahora, poco a poco afrontando un poco más en serio las secuencias de comandos. Mientras tanto, la fórmula me salvó. mucho de tiempo.
En el siguiente ejemplo, la misma fórmula se agrega 3 veces, cada vez con una pequeña variación. El problema que quiero analizar son los diferentes mensajes de error que aparecen al copiar y ejecutar el script de la tabla, incluidas las columnas de fórmula recién agregadas.
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;
)
)
)
);
Captura de pantalla del mensaje de error para la columna de fórmula "QcParameter [%r rel.]_1]" al volver a ejecutar el script de la tabla con columnas de fórmula adicionales:

Captura de pantalla del mensaje de error para la columna de fórmula "QcParameter [%r rel.]_2]" al volver a ejecutar el script de la tabla con columnas de fórmula adicionales:

Captura de pantalla del mensaje de error para la columna de fórmula "QcParameter [%r rel.]_3]" al volver a ejecutar el script de la tabla con columnas de fórmula adicionales:

La razón por la que hago esta larga pregunta es que asumo Debe haber alguna razón por la cual se utiliza la variable "d0Row" en el enfoque n.º. 2, ¿no?Para la aproximación n°. 3 Simplemente eliminé esta variable (vea la captura de pantalla a continuación) y, como resultado, la fórmula se comporta "mucho mejor", es decir, no aparece ningún mensaje de error cuando se agregan nuevas filas ad hoc apuntando y haciendo clic en la tabla de datos.

Mi pregunta entonces es si estoy haciendo algo mal al eliminar la variable "d0Row". En la vida real, estoy trabajando con tablas de datos más grandes y no podré verificar la precisión de cada fila individualmente.