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

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       , $3        reference test method inputs.
  • $R        references 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.
  • null        can 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.
  • +value        applies unary plus.
  • -value        applies 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.ToEven        rounds midpoint values to the nearest even value.
  • MidpointRounding.AwayFromZero        rounds midpoint values away from zero.
  • MidpointRounding.ToZero        rounds toward zero.
  • MidpointRounding.ToNegativeInfinity        rounds toward negative infinity.
  • MidpointRounding.ToPositiveInfinity        rounds 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.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us