Functions in expressions
Functions allow you to perform mathematical operations on the values received from customer attributes or events. Many of those functions duplicate the functions that you can find in programs such as Excel.
Abs
It returns the absolute value of the results of a customer attribute or event. In cases when you want to convert a negative number, you may use absolute value to obtain a positive number in an expression.
Add years
This function returns a date, ahead of the given date by the number of given years
USE CASE: Check whether customers reached the legal age of adulthood.
-
Add the
Add years
function that allows you to perform mathematical operations with regard to dates. -
Then, place the
Now
function within theAdd years
function. In the next field, type in the number which you want to deduct from the current date (year), so you can verify if the customer is of legal age. In some countries, citizens who are 18 years old are considered adults, so in order to deduct 18 years from the current date, we entered-18
. To complete the process, click the Save button. -
Create a segment that consists of adult customers. Such segmentation needs to comprise of 2 steps. In the first step, use
birthdate
as the customer attribute andLess than
as a logical operator. Then select the expression, which you created in previous steps, as the value of theLess than
operator. In the second step, you need to select adult customers among those whose date of birth is available on the contact card. Usebirthdate
as the customer attribute in the second step. Then, determine its value astrue
. Between step 1 and 2 useAND
as a logical operator.
Ceil
Ceiling rounds up the results of expression (e.g. 4.01 will be rounded up to 5).
Exp
The exponential function is a mathematical function denoted by
f(x) = exp(x) or ex
(where the argument x is written as an exponent).
Therefore, the Exp function returns the result of e to the power given in the brackets.
Floor
This function rounds down the results of expressions (e.g. 4.99 will be rounded down to 4).
IfNull
This function returns a boolean value (true or false) that indicates whether the expression contains any valid data (null) and returns true
if it doesn’t.
Ln
This function returns the natural logarithm of a given number.
Max
This function returns the highest value in a set of values.
Min
This function returns the lowest value in a set of values.
Mod
This function returns the remainder after division of one number by another The result has the same sign as the divisor.
Round
This function rounds the expression value to an integer number. According to mathematical principles, values from 01 do 49 are rounded down and values higher than 49 are rounded up.
If
Allows logical comparisons between values. The system creates the desired structure automatically when you select this function.
- After you choose the If function, the expression will be constructed in the specific pattern explained points 2-5.
- The first field in the brackets is taken by the condition that needs to be met, if you want a specific action to happen (3). In this case, the condition consists of the segment of customers who made a purchase on the current day.
- The next place is taken by the expression that is executed when the condition is met/is true (2). In this example, the expression
Last transaction
will be the subject of action. If the condition is true, the value of the last transaction will be multiplied by the number in the next field (4). - This place is taken by the value which will be considered if the condition (2) is true. In this example, the value of the last transaction in the current day will double.
- This place is taken into consideration if the condition (2) is false. If the condition is false, the value of the expression will be equal 0.
Equals
It allows you to check if two values are equal. Returns true
if they are.
Greater
This function checks if the first given value is larger than the second one. Returns true
if it is.
Greater or equals
This function checks if the first given value is larger than or equal to the second one. Returns true
if it is.
Less
This function checks if the first given value is smaller than the second one. Returns true
if it is.
Less or equals
This function checks if the first given value is smaller than or equal to the second one. Returns true
if it is.
Not equals
This function allows you to check if two values are different. Returns true
if they are.
Now
This function allows you to insert the current date or time to your formula.
To string
This function allows you to convert the result of an expression to a string.
To number
This function allows you to convert the result of an expression to a numerical value.
To date
This function converts an ISO date-time string (for example, 2024-11-15T18:00+05:00
or 2024-11-15T18:00Z
) value into a value that’s only a date (2024-11-15
). The date doesn’t have any timezone and the original timezone of the string is ignored when converting into a date.
You can use this function to create expressions whose results will be used in other analyses (for example, segmentations) without consideration of the original timezone of the attribute that was converted to a date - the analysis will treat the date as being in the timezone of the workspace.
To timestamp
A timestamp is a sequence of characters or encoded information identifying when a certain event occurred. Because timestamps may take various formats, you can use this function to convert a date (for example, 2024-11-19
) into a timestamp in the ISO8601 format with the timezone of the workspace (for example, 2024-11-19T01:00:00+01:00
). Later, you can perform actions on dates. It is especially useful when you want to use a time dimension in reports.
You can also use this behavior to recalculate date-times from different timezones into the timezone of the workspace. For example, 2024-11-20T01:30:00+09:00
becomes 2024-11-19T17:30:00.000+01:00
in a workspace whose timezone is +01:00
.
Concat
This function joins two or more strings together and returns the joint string as the result.
Day of month
This function returns the day of the month.
Use this function in event expressions. Later you can use them as a dimension in reports.
Day of week
This function returns the day of the week in the form of a number (values from 1 [Monday] to 7 [Sunday]).
Day of year
This function returns the number of the day of the year (values from 1 to 366).