After reading this article you'll:
  • know what functions are to you
  • be able to use functions in your exercises


Functions allow you to create more dynamic content by manipulating text and numbers.

Saves time and improves engagement through greater personalisation.
  • Many popular functions available for use in calculations and content.
  • Functions can be nested for even greater power

Available Functions

We've grouped the functions into several tables:

  • text functions 
  • number functions 
  • data functions

 Text Functions
Adds together strings to create a new string.

|CONCAT("Rob","Bert")| returns RobBert

Can be any number of strings |CONCAT("rob","ert"," is ", " ","working"," ","today")|  returns "robert is working today"

Use with other nested string functions too |CONCAT("Rob",RIGHT("Bert",3))| returns Robert
Returns a new string for the length of characters starting from the left LEFT(string,length)

|LEFT("Robert",3)| returns "Rob"
Returns the length of a string Example LEN("Robert") returns 6
 Forces strings to lowercase.

|LOWERCASE("HElen")| = "helen"
 Returns part of a string MID(string, start, length) Example MID("Robert",3,4) returns "bert" All string functions cane be nested.

|UPPERCASE(MID("Robert",3,4))|                     returns "BERT"
Replaces occurrences of a string within a string with another string :)

Format is REPLACE(string,what,by)

|REPLACE("i like to eat apples","a","@")| returns "i like to e@t @pples"
Returns a string of length characters starting from the right

Format is RIGHT(string, length)

|RIGHT("Mary had a little lamb",4)| returns "lamb"
Returns the number of times a substring is found within a string.

|STRCOUNT("bird","a little bird sat on my window")| = 1

|STRCOUNT("a","it was a cold night and a bird pecked at an apple")| = 2
 Forces string to all uppercase.

|UPPERCASE("hello")| = "HELLO"

Number Functions
ABS returns the absolute value (ie. removes the negative sign!)

ABS(-1) = ABS(1)
Returns the average in a list of numbers.

e.g AVG(56,27, audience.sender.my_score)

|AVG(partition.custom_data["a"], partition.variables[CONCAT("a.",audience.sender.hash,".my_score")])|

To find an average of an array:

Used to make numbers look attractive - usually to reduce the number of digits after the decimal point. 

Example |FORMAT(3.1276565,"###.##")|  gives 3.13
Forces value to an integer.

for example INT(12.45) = 12

Useful for converting a boolean to a value such as INT(5>2) = 1
MAX() returns largest number.

MAX(5, 4, 1, 12, 56,72) returns 72
MIN() returns the smallest number.

MIN(5, 4, 1, 12, 56,72) returns 1
MOD stands for modulo.

The function returns the remained after a division. The format is MOD(number to be divided, the dividing number).

This is most easily shown with an example such as breaking out hours, mins and secs from a duration:

Hours = |audience.sender.duration|/3600 Minutes = MOD(|audience.sender.duration|/60,60) Seconds = MOD(|audience.sender.duration|,60)
Returns the sum of all values e.g SUM(56,27, audience.sender.my_score)

|SUM(partition.custom_data["a"], partition.variables[CONCAT("a.",audience.sender.hash,".my_score")])|

To find the sum of an array:

Date Functions
Formats dates and times. Please see the DATETIME() article for the full specification

|DATETIME(NOW(),"MMMM d")| returns the current date in the format April 20

You can add and subtract time from NOW() to calculate dates in the past on in the future. For example
|DATETIME(NOW()-"02:00:00:00","dddd")| will subtract two days from today's date and print the day of the week.  For example

"Hey, I know it was 2 days ago you looked into that issue because it was a |DATETIME(NOW()-"02:00:00:00","dddd")| "
 Returns current date and time