Calculations in Forms and Result Grids
A Calculation field computes its value from other fields with an Excel-style formula. It works the same way in every kind of form section:
| Section | Columns | Values are saved as |
|---|---|---|
| Form | One set of fields | Form entries |
| Grid form | One column per subject, e.g. per Sample | Form entries per subject |
| Result grid (+ Section > Add Results > Result grid) | One column per subject, e.g. per Sample | Result values per subject |
A result grid is a grid form whose values, calculated ones included, are saved as result values of the subjects. Everything on this page about grid forms also applies to result grids, including the fm_ variables. Variables are shared across all of them, so a calculation in a result grid can use a field from a form, and the other way round. This page covers the formula language, date and time maths, the helpers for grid forms, the Scifeon functions for entity fields and result values, and the extra variables the fermentation app adds when several fermentations or cultivations share one experiment.
The examples come from fed-batch and shake flask procedures. All names and values are made up.
Basics
Section titled “Basics”Variables
Section titled “Variables”Every field that should take part in a calculation needs a Variable, e.g. od or vol_start.
The formula refers to the field by that variable.
See Naming rules for what a variable may look like.
These field types can be used as variables:
| Field type | Value in a formula |
|---|---|
| Number, Constant | The number |
| Calculation | The calculated value, so calculations can build on each other |
| Date, Time, Date & time | A date serial number, see Date and time |
| Text, Select, Radio, Checkbox | The text |
| Select Entity | The ID of the selected entity, e.g. for ENTITYVALUE |
Variables are shared by the whole experiment. A formula can use a variable from another form section in the same step or from a form in another step. That is why a variable must be unique in the experiment.
The Calculation field
Section titled “The Calculation field”Add a field with the editor Calculation (formula) and enter the formula in Calculation formula (1). Press Ctrl + Space in the formula box to get a list of the variables you can use.

Data type sets what the result is:
- Number (default). Decimal Places controls the rounding.
- Text, e.g. for a pass/fail message.
- Date, Time or Date & time. The result is shown as a date or time. A negative result gives the error results with output type date and/or time cannot be negative.
The value is calculated in the experiment, as soon as a field it depends on changes, and saved with the form. Calculations do not run in a procedure template, because there are no values there. Hover over a calculated value to see the values of the variables it was calculated from.
Functions
Section titled “Functions”Formulas use the same syntax and functions as Excel, e.g. IF, AND, ROUND, AVERAGE, LN, EXP, TODAY and NOW.
The calculation engine is HyperFormula.
The full list of functions .
// The average of the fields a, b and c:AVERAGE(a, b, c)
// "High" or "Low", with Data type "Text":IF(od > 10, "High", "Low")Scifeon adds these functions:
| Function | Returns | Needs |
|---|---|---|
ENTITYVALUE(Entity, "Field") | A field of a selected entity or of a grid column’s subject | - |
RVNUMBER(Subject, "Type", "Unit"), RVTEXT(...) | A result value of a subject | - |
FM_SUM_SAMPLES(RunID, "SampleType", "FieldName") | The sum of a form field over the samples of a run | Fermentation app |
Units are not converted. A formula uses the number as it was entered, whatever unit the field has. If a volume is in mL and a concentration is in g/L, divide by 1000 in the formula yourself, and give the Calculation field the unit of the result.
Empty and N/A values
Section titled “Empty and N/A values”- A calculation that uses a field without a value shows a warning that the variable is missing a value, and has no result until the field is filled in.
- A field marked N/A counts as empty, e.g. as 0 in a sum. The calculation shows the warning Some variables were marked N/A.
- A variable that does not exist gives an error that asks you to make sure the variable is defined.
Date and time
Section titled “Date and time”Dates and times are numbers of days, as in Excel. A Date & time value is the date plus the time as a fraction of a day, so 12:00 is 0.5. That makes the difference between two date and time values a number of days.
// Hours between "Start" (t_start) and "End" (t_end), both Date & time fields:(t_end - t_start) * 24
// Minutes between them:(t_end - t_start) * 1440
// Days since "Thaw date" (thaw), counted from today:TODAY() - thaw
// Planned harvest 14 days after "Inoculation" (dti_inoc), with Data type "Date & time":dti_inoc + 14
// Hours between two Time fields when the end may be after midnight:MOD(t_end - t_start, 1) * 24
// A readable duration, with Data type "Text":INT(t_end - t_start) & " days, " & HOUR(t_end - t_start) & " hours"Grid forms
Section titled “Grid forms”A grid form has one column per subject, e.g. per Sample or per Cultivation, and the same fields in every column. See Multiple Columns for how to set one up. A result grid is a grid form too, and this section applies to it in the same way. A formula in a grid is calculated once per column, with the values of that column.
Column order and quick filters
Section titled “Column order and quick filters”The columns follow the order of the Subjects list in the form settings. Sort that list, e.g. by the time the samples were taken, and the grid keeps that order. All the column helpers below depend on it.
Quick filters above the grid only hide columns. Calculations still see every column, so a hidden column is still the “previous” column of the next one.
Column helpers
Section titled “Column helpers”| Write | Gives | Example |
|---|---|---|
_index | The column number, starting at 0 | IF(_index=0, 1000, vol_prev - feed) |
_id | The ID of the column’s subject | ENTITYVALUE(_id, "name") |
x_prev | x in the previous column | od - od_prev |
x_next | x in the next column | seed_vol_next * 0.35 / seed_od |
x_first | x in the first column | t - t_first |
x_c2 | x in a given column, here the third | od / od_c0 |
In the first column x_prev has no value, and in the last column x_next has none.
They count as empty, and the field shows the warning Value was calculated without _prev variables.
Use _index to choose another value in the first column:
// Volume after each day: 1000 mL at the start, then the previous volume minus the feed:IF(_index=0, 1000, vol_prev - feed)The value is right, but the first column still shows the warning, because the formula refers to vol_prev.
Grid forms and other forms
Section titled “Grid forms and other forms”- A normal form variable in a grid formula has the same value in every column, e.g.
od / od_targetwithod_targetfrom a normal form. - A grid variable in a normal form needs a column:
x_c0,x_c3orx_first. Plainxgives an error, because there is onexper column. - A variable from another grid form is taken from the column with the same number, not from the same subject. Column 3 of one grid reads column 3 of the other. This only works if both grids list the same subjects in the same order. For samples of fermentations and cultivations, use the fm_ variables, which match by sample and run.
One run or several runs in a grid
Section titled “One run or several runs in a grid”_prev, _first and _index work on the columns of the grid.
That is what you want when the grid holds the samples of one fermentation or cultivation.
When the grid holds the samples of several runs, they give the wrong values.
Take a grid with the samples of two bioreactors, sorted by bioreactor:
| Column | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Sample | BR1 day 0 | BR1 day 1 | BR1 day 2 | BR2 day 0 | BR2 day 1 | BR2 day 2 |
_index | 0 | 1 | 2 | 3 | 4 | 5 |
od_prev | - | BR1 day 0 | BR1 day 1 | BR1 day 2 | BR2 day 0 | BR2 day 1 |
od_first | BR1 day 0 | BR1 day 0 | BR1 day 0 | BR1 day 0 | BR1 day 0 | BR1 day 0 |
For BR2 day 0, od_prev is the last sample of BR1, and _index is 3, not 0.
od_first is the first sample of BR1 for every column.
Sorted by time taken, the samples of the bioreactors alternate, and od_prev jumps from one bioreactor to the other in every column.
So IF(_index=0, 0, (t - t_prev) * 24) gives the right sampling interval for one fermentation, and a wrong one as soon as a second fermentation is added to the same grid.
A template that was built for one run must be changed before it is used for several.
The fermentation app solves this with the fm_ variables below.
They work per run, whatever the column order.
Variables per run (fm_)
Section titled “Variables per run (fm_)”When they are available
Section titled “When they are available”The fm_ variables are added to a grid form or a result grid when at least one column’s subject is a Sample that belongs to a Fermentation or a Cultivation.
A sample belongs to a run through its Fermentation or Cultivation field.
A derived sample, e.g. a supernatant, belongs to the run of its root sample.
For each sample, the samples of the same run are put in a group, in the column order of the grid.
Only the samples in this grid form count.
A sample whose run cannot be found gets no fm_ variables.
Ctrl + Space lists the fm_ variables when the grid’s Entity Class is Sample.
The variables
Section titled “The variables”| Variable | Gives |
|---|---|
fm_index | The position of the sample among the samples of its run in this grid, starting at 0 |
fm_dtiInoculation | The inoculation date and time of the sample’s run |
fm_<var> | The field <var> of the sample’s run, from a grid form with Entity Class Fermentation or Cultivation |
fm_prev_<var> | The field <var> of the previous sample of the same run |
fm_first_<var> | The field <var> of the first sample of the same run |
<var> in fm_prev_<var> and fm_first_<var> can be any variable in a grid form with Entity Class Sample in the experiment, including the form itself and Calculation fields.
For the grid above, fm_index is 0, 1, 2, 0, 1, 2, and for BR2 day 0 fm_prev_od has no value and fm_first_od is the OD of BR2 day 0.
For the first sample of each run, fm_prev_<var> has no value.
It counts as empty, like a field marked N/A, and the field shows the warning Some variables were marked N/A, also when the formula does not use the value there.
Run values in the sample grid
Section titled “Run values in the sample grid”Values that belong to the run, such as the start volume, the feed concentration or the limits of a run, go in a grid form with one column per run:
- Add a form to a step that has the Fermentations or Cultivations as input or output.
- In the form settings, enable the grid, set Entity Class to Fermentation or Cultivation, and pick the runs as Subject Sources.
- Add fields with variables, e.g.
V0for the start volume.
In the sample grid, fm_V0 is then the start volume of each sample’s own run.
Worked examples
Section titled “Worked examples”The examples use these fields:
| Form | Field | Variable | Field type |
|---|---|---|---|
| Run grid (Entity Class Cultivation) | Start volume (mL) | V0 | Number |
| Run grid | pH low limit | ph_lo | Number |
| Run grid | pH high limit | ph_hi | Number |
| Sample grid (Entity Class Sample) | Time taken | Tt | Date & time |
| Sample grid | Added since last sample (mL) | Ta | Number |
| Sample grid | Sample volume (mL) | s | Number |
| Sample grid | OD600 | od | Number |
| Sample grid | Titer (g/L) | titer | Number |
| Sample grid | pH | ph | Number |
Each grid can be a grid form or a result grid. Use a result grid for the sample grid when the measured and calculated values should be saved as results of the samples.
Culture volume (vol, Number, mL).
The first sample of each run starts from the run’s start volume, the next ones from the previous sample’s volume:
IF(fm_index=0, fm_V0, fm_prev_vol) + Ta - sfm_prev_vol refers to the field’s own variable in the previous sample, so the volume carries over from sample to sample within each run.
Culture age in hours (age, Number, h):
(Tt - fm_dtiInoculation) * 24Specific growth rate and doubling time (mu, Number, 1/h, and td, Number, h):
// Growth rate since the previous sample of the same run:LN(od / fm_prev_od) / (age - fm_prev_age)
// Doubling time:LN(2) / mu
// Doubling time over the whole run, from the first sample:(age - fm_first_age) * LN(2) / LN(od / fm_first_od)The first sample of each run has no previous sample, so mu divides by zero there and shows an error.
The whole-run doubling time divides by zero in the first sample too.
Volumetric productivity since the previous sample (prod, Number, g/L/h):
(titer - fm_prev_titer) / (age - fm_prev_age)Total added since the first sample (Number, mL):
IF(fm_index=0, 0, Ta + fm_prev_tot_added)Give the field the variable tot_added, so it can refer to its own previous value.
In range? (Data type Text), with limits that can differ per run:
IF(AND(ph >= fm_ph_lo, ph <= fm_ph_hi), "OK", "Out of range")Culture age from the sample’s own time taken, instead of a form field, with ENTITYVALUE:
(ENTITYVALUE(_id, "dtiTaken") - fm_dtiInoculation) * 24Using fields of a selected entity (ENTITYVALUE)
Section titled “Using fields of a selected entity (ENTITYVALUE)”ENTITYVALUE(Entity, "Field") returns a field of the entity selected in a Select Entity field, so a calculation can use e.g. the purity of the Batch a user picked.
- Entity is the Variable of a Select Entity field. In a grid form,
_idgives each column’s subject. - Field is the field’s accessor, e.g.
"purityValue", or its name, e.g."Purity value", in quotes. Upper and lower case do not matter. The accessor is shown when the field is created under Fields, and it stays the same if the field is renamed, so it is the safer choice.
// The name of the Batch selected in the Select Entity field with the variable batch:ENTITYVALUE(batch, "name")
// Grams of the Batch needed for 10 g of pure product, from its custom field "Purity value" (in %):10 / (ENTITYVALUE(batch, "purityValue") / 100)
// Days until the Batch's custom field "Expiry date":ENTITYVALUE(batch, "Expiry date") - TODAY()
// In a grid form: the name of each column's SampleENTITYVALUE(_id, "name")Number fields give numbers and date fields give dates you can calculate with. Other fields give text.
Metadata or current value. If the field is shown as Entity Metadata on the Select Entity field, ENTITYVALUE uses the stored metadata, i.e. the value shown in the form. When the entity has changed, the user clicks View information changes on the field and accepts, and the calculation updates at once. Every other field gives the entity’s current value. If such a value changes after the form was filled in, the experiment shows There are outdated calculations, and Apply Calculations updates the calculated fields, as for result values.
So, if a calculation must keep the value the user saw when filling in the form, show the field as Entity Metadata. If it should follow the entity, do not.
Limits and errors:
- ENTITYVALUE works in form calculations, not in the Spreadsheet.
- The Entity must be a variable. A typed-in ID, e.g.
ENTITYVALUE("BAT001", "name"), gives#VALUE. - Until an entity is selected, the calculation shows an error, as for any other empty variable. A Select Entity field that allows several entities has no single entity to read, and always shows this error.
- A field that does not exist on the entity class gives
#VALUEnaming the field. - A field without a value gives
#N/A.
Using result values (RVNUMBER and RVTEXT)
Section titled “Using result values (RVNUMBER and RVTEXT)”RVNUMBER(Subject, "Type", "Unit") returns the number of a result value, and RVTEXT(Subject, "Type", "Unit") returns its text.
Both also work in the Spreadsheet.
- Subject is the ID of the entity the result belongs to, e.g. a Sample: the Variable of a Select Entity field,
_idin a grid form, or an ID in quotes, e.g."S00123". - Type is the result type, e.g.
"Mass". Upper and lower case do not matter, and the unit may be part of it, e.g."Mass [mg]". - Unit is optional. Give it when the same result type is stored in more than one unit; otherwise the first value found is used.
// The mass in mg of the Sample selected in the Select Entity field with the variable sample:RVNUMBER(sample, "Mass", "mg")
// In a grid form: the color recorded for each column's SampleRVTEXT(_id, "Color")The functions find the result values uploaded in this experiment, and every result value of the entities used as inputs or outputs of its steps, including results from other experiments.
A result that is not found, or has no value, gives #N/A.
When results in the experiment are saved or uploaded, also by a colleague, form calculations that use them show There are outdated calculations, and Apply Calculations updates them. In a Spreadsheet, the cells recalculate.
Sum over the samples of a run (FM_SUM_SAMPLES)
Section titled “Sum over the samples of a run (FM_SUM_SAMPLES)”FM_SUM_SAMPLES(RunID, "SampleType", "FieldName") adds up a number field over the samples of one run, e.g. the total volume taken out for sampling.
- RunID is the ID of the Fermentation or Cultivation. In a run grid, use
_id. - SampleType is the sample’s Type, e.g.
"Broth". Upper and lower case do not matter. - FieldName is the field’s Name, not its variable, written exactly as in the form.
// In the run grid: the volume taken out of each run by the Broth samplesFM_SUM_SAMPLES(_id, "Broth", "Sample volume")
// The same for one run, by its ID:FM_SUM_SAMPLES("CUL0012", "Broth", "Sample volume")- It counts the samples that are subjects of a form in this experiment, and their saved values. After a save, the sum updates.
- Empty and N/A values are skipped. A value that is not a number gives
#VALUE. - No matching samples gives 0.
- It also works in the Spreadsheet.
Limitations
Section titled “Limitations”fm_variables and FM_SUM_SAMPLES need the fermentation app, and samples that belong to a Fermentation or a Cultivation.fm_variables only exist in grid forms and result grids whose columns are samples. They are not available in normal forms or in the Spreadsheet. In a Spreadsheet, read form values with FORMV.fm_prev_andfm_first_only look at the samples of the same run in the same grid form, in column order. A sample of the run in another step’s grid does not count.fm_dtiInoculationand the list of runs are read from the server and kept for up to a minute. A change to a run’s inoculation time can take that long to show up in the form._prev,_next,_first,_indexand variables from other grid forms work by column number, not by subject.- Quick filters do not change calculations.
- Units are not converted.
- Calculations only run in experiments, not in procedure templates.