# How does the Formula Field work in Assessments?

Contents

Here’s how to add Formula Fields to your assessments, and we also included some examples so you can put formulas to work in your own assessments: ### Overview of Formula Fields

The Formula Field gives you a lot of flexibility for customizing your assessment results, based on the answers submitted in the assessment.

You can customize how your assessment will be scored, add formula fields within your assessment, and set up formulas to trigger different actions like adding tags, assigning plans, or assigning clients to groups.

### How to Specify Client Responses in Your Formulas

You can use clients’ exact responses (VALUE), OR the points scored (POINT VALUE) from their responses into your formulas. Here’s how to set them up:

• To get the VALUE of a question, enter `qv#`.
For example: `qv1` is the client’s answer for question 1. `qv23` is the client’s answer to question 23. etc.
• To get the POINT VALUE of a question that you have set up with scoring, enter `q#`.
For example: `q1` is the point value of question 1 based on how the user answered. `qv33` is the point value for question 33 based on how the user answered.

### Common Formula Examples

Simple Math:

Formula Field: q2 + (q3 / q4)

If q2 = 3; q3 = 10; q4 = 5; then your formula would return an answer of 5.

Take the Minimum of Answers Provided:

Formula Field: min(q2, q3, q4)

If q2 = 3; q3 = 10; q4 = 5; then your formula would return an answer of 3, since that’s the lowest number.

Formula Field: roundTo(q10, 2)

If q10 = 42.3245215, then your formula would return an answer of 42.32.

Combine Multiple Formulas:

You can take the value of one formula and plug it into another formula!

For example, if Question 6 is a Formula Field, and you want that answer plugged into Question 7, another Formula Field, you can use qv6 to grab the VALUE from the formula result in Question 6 and plug it into the formula for Question 7:

Question 7: Formula Field: qv6 + 5

If the answer to Question 6’s Formula Field calculation comes out to 10, then the formula for Question 7 would return 15.

### List of ALL Pre-Defined Functions

Here are all the possible pre-defined functions that you can plug into a Formula Field (source):

Function Description
random(n) Get a random number in the range [0, n). If n is zero, or not provided, it defaults to 1.
fac(n) n! (factorial of n: “n * (n-1) * (n-2) * … * 2 * 1”) Deprecated. Use the ! operator instead.
min(a,b,…) Get the smallest (minimum) number in the list.
max(a,b,…) Get the largest (maximum) number in the list.
hypot(a,b) Hypotenuse, i.e. the square root of the sum of squares of its arguments.
pyt(a, b) Alias for hypot.
pow(x, y) Equivalent to x^y. For consistency with JavaScript’s Math object.
atan2(y, x) Arc tangent of x/y. i.e. the angle between (0, 0) and (x, y) in radians.
roundTo(x, n) Rounds x to n places after the decimal point.
map(f, a) Array map: Pass each element of `a` the function `f`, and return an array of the results.
fold(f, y, a) Array fold: Fold/reduce array `a` into a single value, `y` by setting `y = f(y, x, index)` for each element `x` of the array.
filter(f, a) Array filter: Return an array containing only the values from `a` where `f(x, index)` is `true`.
indexOf(x, a) Return the first index of string or array `a` matching the value `x`, or `-1` if not found.
join(sep, a) Concatenate the elements of `a`, separated by `sep`.
if(c, a, b) Function form of c ? a : b. Note: This always evaluates both `a` and `b`, regardless of whether `c` is `true` or not. Use `c ? a : b` instead if there are side effects, or if evaluating the branches could be expensive.

Now you can supercharge your assessments using formulas!

Updated on October 30, 2020