Formulas

This is a reference page for the formulas that can be used in Insight. Click here if you would like to see examples for the common formulas used for branching logic.

Arithmetic Operators

Formula

Description

Usage

Result

()

Order of Operations Grouping - any operators inside of the parenthesis will have priority

(1+2)*3

9

*, /, %

Multiplicative operators

·        Use * for multiplication

·        Use / for division

·        Use % for modulo operation (this operation gives you the remainder after dividing the two numbers)

 

·        2 * 2

·        9 / 3

·        5 % 2

 

·        4

·        3

·        1

+, -

Additive operators

·        Use + for addition

·        Use - for subtraction

 

·        2 + 2

·        5 - 4

 

·        4

·        1

datediff

See DateDiff Operator section below for details

datediff([fieldname1], [fieldname2], “h”, true)

the difference in hours

(based on unit) between fieldname1 and fieldname2

Abs

Returns the absolute value of a specified number.

Abs(-1)

1

Ceiling

Returns the smallest integer greater than or equal to the specified number.

Ceiling(1.5)

2

Exp

Returns e raised to the specified power.

Exp(1)

2.71828

Floor

Returns the largest integer less than or equal to the specified number.

Floor(1.5)

1

IEEERemainder

Returns the IEEE Remainder resulting from the division of a specified number by another specified number.

IEEERemainder(5, 2)

IEEERemainder(3, 2)

1

-1

in

Returns whether an element is in a set of values.

in(1 + 1, 1, 2, 3)

true

Log

Returns the logarithm of a specified number.

Log(1, 10)

0

Log10

Returns the base 10 logarithm of a specified number.

Log10(1)

0

Max

Returns the larger of two specified numbers.

Max(1, 2)

2

Min

Returns the smaller of two numbers.

Min(1, 2)

1

Pow

Returns a specified number raised to the specified power.

Pow(3, 2)

9

Round

Rounds a value to the nearest integer or specified number of decimal places. The mid number behavior can be changed by using EvaluateOption.RoundAwayFromZero during construction of the Expression object.

Round(variable, digits)

Round(3.2225, 2)

3.22

Sign

Returns a value indicating the sign of a number.

Sign(-10)

1

Sqrt

Returns the square root of a specified number.

Sqrt(4)

2

Truncate

Calculates the integral part of a number.

Truncate(1.7)

1

 

Comparison Operators

Formula

Description

Usage

Result

if

Returns a value based on a condition.

if(3 % 2 = 1,
'value is true', 'value is false')

'value is true'

=, ==, !=

Equality Operators

For single value question:

([question] == 5)

Returns true or false

<, >, <=, >=

Relational operators - Used for True/False results

·        Use < for less than

·        Use > for greater than

·        Use <= for less than or equal to

·        Use >= for greater than or equal to

·        5 < 10

·        1 > 4

·        -2 >= 0

·        6 <= 6

·        True

·        False

·        False

·        True

&&, and

Logical and

·        Do not use uppercase ‘AND’ for logical operations

Returns False if one side argument is false

·       (datediff(today, [quitDate]…)) && ([smokedYesterday])

 

||, or

Logical or

·        Do not use uppercase ‘OR’ for logical operations

Returns True if one side argument is true

·       ([value] > 3) || ([smokedYesterday])

 

 

Reference Operators

Formula

Description

Usage

Result

[fieldname]

Access the value of the single-choice variable (Radio, Dropdown) from the current Assessment

[question_1]

 

[:]

Gives a default value to fields that haven’t been answered yet

[fieldname:0]

0 if no responses

[*]

Gets values outside of the current Assessment

[[*]fieldname]

 

Checkbox

[fieldname(x)]

Returns true or false if multiple choice response option was selected

For Checkbox question type:

[fieldname(value)] == 1

 

last([])

Returns the most recent response value

last([fieldname])

 

Trigonometry Functions

Acos

Returns the angle whose cosine is the specified number.

Acos(1)

0

Asin

Returns the angle whose sine is the specified number.

Asin(0)

0

Atan

Returns the angle whose tangent is the specified number.

Atan(0)

0

Cos

Returns the cosine of the specified angle.

Cos(0)

1

Sin

Returns the sine of the specified angle.

Sin(0)

0

Tan

Returns the tangent of the specified angle.

Tan(0)

0

Formula

Description

Usage

Result

datediff

units

·        "y" years
1 year = 365.2425 days

·        "M" months
1 month = 30.44 days

·        "d" days

·        "h" hours

·        "m" minutes

·        "s" seconds

 

dateformat

·        "ymd" Y-M-D (default)

·        "mdy" M-D-Y

·        "dmy" D-M-Y 

 

returnsSignedValue

·       boolean parameter (true/false) as to whether return the signed value or the positive value

 

useLocalTime

·       boolean parameter (true/false) as to whether the parameter Times should be adjusted from UTC to local time of the device

datediff(
date1,
date2,
units,
dateformat*,
returnSignedValue,
useLocalTime*
)

·        includes optional parameters

 

Example without optional parameters:

 

datediff([fieldname1], [fieldname2], “h”, true)

the difference in ‘units’ between date1 and date2

 

 

 

 

 

 

 

 

the difference in “hours”  between fieldname1 and fieldname2

returns as positive or negative value

dateFormat

The date format is used to display date time in desired format.

First parameter is the date and or time value that needs to be formatted.

Second parameter is used to specify the format in which information is to be presented.

Additionally, when the PI does not want to display UTC Time on date or time picker questions, an additional parameter can be utilized to control presentation of information.

  • Using the parameter of false will preserve PT’s local time, to display the time as PT entered it.

$dateFormat([fieldname],'MM/dd/yyyy', false)$

 

 

$dateFormat([fieldname], 'hh:mm tt', false)$

 

 

 

 

 

$dateFormat([fieldname], 'h:mm tt', false)$

Shows the current date

 

 

Shows the current time not in UTC time in the format below.

Example: 09:00 pm

 

 

Shows the current time not in UTC time in the format below.

Example: 9:00 pm