Mathematical Expressions

Expressions are mathematical formulas that are used to calculate values for specific columns in the Item, Formula, or Project parameters. These are faster than Equations.

By default, the Expressions are defined for the Value column. You can also define calculations for the Min Val, Max Val, and the Attribute columns on Items, Formulas, and Projects.

Defining Parameters

Simple Parameters
The simplest parameter is the name of another Parameter.

For example:

If there is a Parameter named CARBS_PER_SERVING, you can define an Expression as:

[CARBS] * [SERVING_SIZE]

This retrieves the values of CARBS and SERVING_SIZE, multiplies them, and displays the result in the Value column.

Accessing Specific Columns
To use values from a different column, append a period and the column name after the Parameter name.

For example:

[CARBS.ATTRIBUTE6] accesses the value in the ATTRIBUTE6 column of the CARBS parameter.
Note: You must use square brackets, especially for parameters with special characters.

Mathematical Processing

Mathematical processing is powered by the open-source utility NCalc, which supports a comprehensive list of operators, values, and functions. For more information, refer to Ncalc functions.

Additionally these custom functions are introduced to the Optiva application:
Default()
  • Returns 0.0 for blank values if one argument is provided.
  • Returns the second argument if the first is empty.
  • Example: Default([CARBS.ATTRIBUTE6], Default([CARBS])) prioritizes values in ATTRIBUTE6, falls back to CARBS, and finally returns 0.0 if both are blank.
IsBlank()
Returns True or False depending on whether a value is empty.

Blank Values and Calculations

For most Expressions, if a parameter value is blank, the result is null, and the corresponding column is set to null.

If the column is the Value column, the Level column is set to Pending. You can use the Default() function to define required and optional parameters.

Example:

[FAT_SAT] + [FATS_UNSAT] + Default([FATS_TRANS])

The calculation requires FATS_SAT and FATS_UNSAT. If both are specified, calculation is performed even if FATS_TRANS is missing.

Additional Tips

Lab Behavior
Material Rollup Parameter: Processed during Item or Project calculations.
Equation Total Parameter: Processed during Formula calculations after rollups.
Informational Parameter: Processed for Items and Formula calculations.
Parameters must appear in the correct order for dependent calculations (example: [A] + [B] requires A and B to be defined before C).
Expression Tab
Use the Expression Tab to test the parameters. You can specify sample values and click the Test Expression option for results.
Note: Syntax errors or undefined parameter codes can generate errors when you save the expression.
Constants in Expressions
Use decimals for numeric constants.
Example: [CARBS] / 100.0 instead of [CARBS] / 100.
Error Handling
Ensure a result column is added to the left-hand table. Syntax errors, missing parentheses, or invalid references prevents saving.