Calculation Formulas
Calculation formulas are used on test method outputs when a result should be copied, calculated, rounded, formatted, or conditionally reported from one or more inputs.
Use this guide as a reference for the formula syntax available in LabHQ. For worked examples, see the separate article: Calculation Formula Examples.
Contents
- Where Formulas Are Used
- Input And Result References
- Text And Numeric Values
- Operators
- Conditions
- Functions
- Rounding Options
- Good Practice
Where Formulas Are Used
Formulas can be used in two places on a test method output.
Result Calculation
The Result Calculation field calculates the stored result for the output. It can copy an input directly, perform numeric calculations, return text, or return a value based on a condition.
Inputs are referenced using a dollar sign followed by the input number, such as $1 , $2 , and $3 .
Display Calculation
The Display Calculation field formats the result for reporting. Display calculations can reference the calculated result using $R .
Display calculations are useful when the stored result should be shown with rounding, units, pass/fail text, grades, or reporting statements such as "<LOQ" .
Input And Result References
$1,$2,$3reference test method inputs.$Rreferences the calculated result in a display calculation.- The number after
$must match the input number on the test method. - Inputs with a Display On value of Workbook should not be used in output calculations.
Text And Numeric Values
- Text values must be enclosed in double quotes.
- Numbers should use a decimal point, not a comma.
nullcan be used to represent an empty value.- Function names are not case-sensitive.
Operators
Arithmetic Operators
+adds numbers or joins text values together.-subtracts one value from another.*multiplies values./divides one value by another.+valueapplies unary plus.-valueapplies unary minus.
Comparison Operators
<means less than.<=means less than or equal to.>means greater than.>=means greater than or equal to.==means equal to.!=means not equal to.
Logic Operators
&&means AND. Both conditions must be true.||means OR. At least one condition must be true.
Grouping And Separators
(...)groups part of a formula or encloses function arguments.,separates function arguments.::creates an input range for functions that accept multiple values.
Conditions
Use a conditional expression when a formula should return different values based on a condition.
condition ? valueWhenTrue : valueWhenFalse
Conditional expressions can return numbers or text. If the formula returns text, make sure each branch returns the text that should be reported.
Functions
Summary Functions
| Syntax | Description |
|---|---|
MIN(value, ...) |
Returns the lowest numeric value. At least one value is required. |
MAX(value, ...) |
Returns the highest numeric value. At least one value is required. |
AVG(value, ...) |
Returns the mean average of numeric values. At least one value is required. |
SUM(value, ...) |
Returns the total of numeric values. At least one value is required. |
STDEV(value, ...) |
Estimates standard deviation based on a sample. At least two values are required. |
STDEVP(value, ...) |
Calculates standard deviation based on a population. At least one value is required. |
CORREL(value, ...) |
Calculates the correlation coefficient for two numeric series. Provide an even number of values. The first half are the x-values and the second half are the y-values. |
Numeric Functions
| Syntax | Description |
|---|---|
ABS(value) |
Returns the absolute value. |
FLOOR(value) |
Rounds down to the largest whole number less than or equal to the value. |
POW(value, exponent) |
Raises a value to a power. |
SQRT(value) |
Returns the square root. |
Conversion Functions
| Syntax | Description |
|---|---|
STR(value) |
Converts a value to text. |
NUM(value) |
Converts a value to a number. |
Use NUM only when a string input contains a numeric value that must be calculated. If the input may contain text such as "BDL" or "NQ" , check for that text before converting the value.
Rounding Functions
| Syntax | Description |
|---|---|
ROUND(value) |
Rounds to the nearest whole number using MidpointRounding.ToEven. |
ROUND(value, digits) |
Rounds to the specified number of decimal places using MidpointRounding.ToEven. |
ROUND(value, midpointRounding) |
Rounds to the nearest whole number using the specified midpoint rounding option. |
ROUND(value, digits, midpointRounding) |
Rounds to the specified number of decimal places using the specified midpoint rounding option. |
Rounding Options
When ROUND is used without a rounding option, midpoint values are rounded using MidpointRounding.ToEven .
The following midpoint rounding options are available:
MidpointRounding.ToEvenrounds midpoint values to the nearest even value.MidpointRounding.AwayFromZerorounds midpoint values away from zero.MidpointRounding.ToZerorounds toward zero.MidpointRounding.ToNegativeInfinityrounds toward negative infinity.MidpointRounding.ToPositiveInfinityrounds toward positive infinity.
Good Practice
- Use matching outputs when the output should report an input exactly.
- Use numeric inputs for values that need to be included in calculations.
- Use double quotes around text values.
- Use
==when comparing values. - Use parentheses to make complex formulas easier to read.
- Use display calculations for report formatting, units, pass/fail wording, and result grading.
- Test calculations before publishing a test method.