Skip to main content

What’s New

Qrvey 8.7
Version 8.7 of the Qrvey platform is now available to customers! This version includes new features including area charts, the ability to pivot and export data, as well as numerous bug fixes and performance improvements.
Learn More
Qrvey 8.6
Version 8.6 of the Qrvey platform is now available to customers. This version includes several new feature enhancements and performance improvements.
Learn More
Required Update for 8.5.1
Attention 8.5.1 customers: for any 8.5.1 instance deployed prior to 08/05/2024, an update is required to ensure you are running the latest images.
Learn More
Qrvey 8.5
Version 8.5 (LTS) of the Qrvey platform is now available to customers. This version includes several new features and performance improvements.
Learn More
End-of-life Schedule
We've added a new article that lists the features and endpoints that have been scheduled for deprecation. All features and endpoints will be supported for (1) year after the release date of the LTS version that contains the alternative.
Learn More
Version: 8.0

Formulas

You can find Formulas in the Analyze section of Qrvey Composer, as well as the Chart Builder, to create calculated columns that can be used like any other column of data.

Use Cases

Formulas can be used to segment data, to convert the data type of a field (such as converting a string to a date), to aggregate data, to filter results, to calculate ratios, and much more.

Basic Components

  1. Functions - Statements used to transform the values or members in a field.
  2. Columns - Dimensions or measures (columns) from your data source.
  3. Operators - Symbols that denote an operation.

Examples

  • Extracting a Month From a Date

The function that returns any part of a date or date/time value is dateFormat:
Syntax: dateFormat(date_value, 'format')
Example: orderDate is a date data type and we need to extract the month part of it to use on the x-axis of a bar chart.
We can create a new formula as dateFormat( [orderDate], 'MM') and call it orderMonth. The new column will list the month number of order date (i.e. 01 for January, 02 for February, etc.)

  • Aggregate Values of All Rows

You can get the aggregate of a column based on all rows of data to use in a calculation. An example use case of this would be calculating the percentage of one product's inventory to all products. All aggregate functions start with agg_.
Syntax: agg_sum(value)
Example: quantityInStock is a number data type and we need to calculate the percentage of each product's quantity to the entire inventory of products. We can create a new formula as: [quantityInStock]*100/agg_sum( [quantityInStock]) and call it quantityPercent.

  • Concatenating Text Columns

The simple + sign can be used to stitch strings of text together. An example would be creating full name from first and last name columns.
Syntax: value1 + value2 + value3...
Example: contactFirstName and contactLastName are text type columns and we want to concatenate these together for searches with the last name at the beginning to facilitate sorting. We can create a new formula as: [contactLastName]+' , '+ [contactFirstName] and call it contactName. The returned result for a contact with first name ‘John’ and last name ‘Doe’ will be ‘Doe, John’.

  • Using Other Scripting Functions

Painless scripting functions can be used to create calculated columns. An example of this use case would be to use the if function to return a value based on a condition.
Syntax: if (condition) {return result1;} else {return result2;}
Example: orderDate and shippedDate are date type columns that contain order and shipping dates in an ERP system. We want to decide in which cases our shipping department did a good job and for which orders it reacted too slow.

The Function:
if(dateDiff( [orderDate],isNull([shippedDate],now()),'DAYS')<=3) {return 'fast';} else {return 'slow';}
First, make sure that _null_ values of shippedDate are replaced with a datavalue (now) and then run a comparison to get the result fast when shipping happened within three days of taking the order and slow in all other cases.

Notes

  1. When using the action commands to add functions and columns to the formula dialog (rather than typing it in) pay attention to the position of your cursor. Functions are added within parentheses and unless you move your cursor inside the parentheses before adding columns or typing, you may create a syntax error in your formula. Make sure you test your formula before saving it!

  2. Even if a Painless function is not listed in the Functions list, it may still be supported. Don't hesitate to try. For example [orderDate].dayOfWeek is a perfectly acceptable formula, although it's not listed. It returns the number of weekdays of the date value. Note that this example also illustrates the use of the Apply operator (.) as an alternative way to invoke a function.

Syntax

Fields/Columns - use [ ] around the field or column name, e.g. [Sales].
Functions - function names are case sensitive and must be followed by a bracketed argument list, e.g. sum([Items]) or avg([Temp]).
Operators - the following table shows the available operators. Note that normal operator precedence applies. For example, in the expression 32 + 5 * [Temperature] / 9, 32 is added to five ninths of [Temperature].

SymbolOperation
.Apply the function following the dot to the string/text value before the dot.
*Multiplication of two numbers.
/Division of two numbers.
+Addition of two numbers.
-Subtraction of two numbers, or negation of a number.
==Test equality of two values.
>Test if the first value is greater than the second value.
<Test if the first value is less than the second value.
>=Test if the first value is greater than or equal to the second value.
<=Test if the first value is less than or equal to the second value.
!=Test inequality of two values.
^Bitwise exclusive or (XOR) of two values.
ANDLogical and of two values.
ORLogical or of two values.
NOTLogical not of a value.
( )Evaluate the bracketed expression before applying operators to it.

Date And Time Patterns

dateFormat function accepts a format argument that determines how the formatted date (and time) is going to be displayed. A quick reference exists in the Formula Builder when the function is selected, but here is a full reference of all possible values for format and an example of how it affects the date string.

Note 1: You may use single, or double quotes around the format string.
Note 2: All dates are treated as GMT in Qrvey. Because of that, the three formats: z, Z, X return values for GMT.

LetterDate or Time ComponentPresentationExamples
GEra designatorTextAD
y, YYearYear1996; 96
MMonth in yearMonthJuly; Jul; 07
wWeek in yearNumber27
WWeek in monthNumber2
DDay in yearNumber189
dDay in monthNumber10
FDay of week in monthNumber2
EDay name in weekTextTuesday; Tue
eDay number of week (1 = Monday, ..., 7 = Sunday)Number1
aAM/PM markerTextPM
HHour in day (0-23)Number0
kHour in day (1-24)Number24
KHour in AM/PM (0-11)Number0
hHour in AM/PM (1-12)Number12
mMinute in hourNumber30
sSecond in minuteNumber55
SMillisecondNumber978
zTime zoneGeneral time zonePST; GMT-08:00
ZTime zoneRFC 822 time zone-0800
xTime zoneiso 8601 time zone-08; -0800; -08:00

Format strings can be combined to give you the format that you want. For example: dateFormat(“07/04/2001”, "EEE, MMM d, ‘’yy") results in: Wed, Jul 4, ‘01

* dateFormat reference: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Supported Functions

Creating a Formula

  1. To create a formula click on the uppercase sigma letter.

  1. Click on Create Formula.
  1. Look for the function you want to insert, choose it, check it and click Add to formula.
  1. Look for the column you want to Insert and add it to the parentheses. Add any additional parameters that are needed for the function (e.g. dateFormat function needs a format parameter that can be set to 'MM' if the date is to be formatted as a month - or 'yyyy' if it has to be formatted as a 4-digit year)
  1. Test the formula. Don’t forget to name your formula, and Save it.
  1. Use your new formula. Note that newly added columns are hidden by default and have to be made visible from the Select Columns command.

Adding a Nested Formula

You can create nested formulas (formulas inserted within formulas) by copying and pasting the syntax of one formula into another one or by selecting one of the formula columns the same way you do to insert a regular dataset column into a formula’s syntax.

  1. Just look for the formula column you want to insert and add it in the parentheses like you would with any other data column.
  2. Add any additional parameters that are needed for the function.
  3. Test the formula. Don’t forget to name and save your formula.