Expressions List
Last updated
Last updated
You can use a variety of functions when writing an expression to compare or transform data during the processing of a rule.
The following functions are currently supported within an expression:
These will compare one instance to another and will evaluate to either True or False.
These operators are not available for all data types. The table below shows what operators can be used with what data. Operators support either a symbol representation (e.g. =) or a natural language equivalent. For , see the date functions.
Data type of output: Boolean (true/false)
=
equals
is equal to
!=
does not equal
is not equal to
>
gt
greater than
is greater than
>=
gte
greater than or equal to
is greater than or equal to
<
lt
less than
is less than
<=
lte
less than or equal to
is less than or equal to
Confirm a string contains a set of characters. Partial matching enables you to check the presence of a word or set of characters to infer facts.
Data type of output: Boolean (true/false)
Example
includes(%COMPANY_NAME, ‘LTD’)
In this example you could infer a company is Public Limited Company by checking if a company name contains 'LTD' in the name. E.g. given a company name of Rainbird Technologies LTD
the function will evaluate to true
.
Matching is case sensitive and will include whitespace before, within and after the search string.
E.g. Given a search string of ' Ltd'
a company name of Rainbird Technologies LTD
(uppercase) or Rainbird TechnologiesLtd
(no whitespace before) would evaluate to false
.
To check the absence of a set of characters, = false
can be added to the end of the expression.
e.g. includes(%EMAIL_ADDRESS, '@rainbird.ai') = false
can determine a person is not an internal user when the email does not contain the company name.
Join values together into a single output using the +
operator. Concatenation enables you to combine variables with text strings to create dynamic output.
Data type of output: String
Example %FIRST_NAME + ' ' + %LAST_NAME
In this example you could create a full name by joining the first and last name with a space in between. E.g. given a first name of John
and a last name of Smith
the expression will evaluate to John Smith
.
Concatenation can join any number of strings and variables together. E.g. 'Claim ' + %CLAIM_ID + ' has been ' + %APPROVAL_STATUS + ' with a payout amount of £' + %PAYOUT_AMOUNT
could produce Claim CL-8932 has been APPROVED with a payout amount of £5,750
.
Dates, numbers and truth types will automatically convert to strings. Dates will display as a timestamp.
The following mathematical functions are available to use with number concepts only.
Data type of output: number
Add
+ Add two numbers together
10 + 5 = 15
Subtract
- Subtract one number from another
2 - 1 = 1
Divide
/ Divide one number by another
6 / 2 = 3
Multiply
* Multiple one number by another
4 * 2 = 8
Round
round(%X, %Y) Round X to the nearest integer. You can specify Y to round to Y number of places. If Y is not specified, 0 is assumed.
round(123.4) = 123 or round(123.4567,2) = 123.46
Ceiling
ceil(%X) Round X towards plus infinity
ceil(4.2) = 5 ceil(-4.2) = -4
Floor
floor(%X) Round X towards minus infinity
floor(4.2) = 4 floor(-4.2) = -5
Absolute
abs(%X) Calculate the absolute value of X
abs(4.2) = 4.2 abs(-4.2) = 4.2
Minimum
min(%A,%B,%C...) Calculate the minimum value in a set of values
min(6,4,2,15,11) = 2
Maximum
max(%A,%B,%C...) Calculate the maximum value in a set of values
max(6,4,2,15,11) = 15
Modulus
mod(%X,%Y) Calculate the modulus (the remainder of an integer division) of X/Y
mod(5,2) = 1
Power
pow(%X,%Y) Calculate the power of X to Y (X^Y)
pow(10,3) = 1000
Square root
sqrt(%X) Calculate the square root of X
sqrt(64) = 8
Factorial
factorial(%X) Calculate the factorial of X
factorial(4) = 24
Tangent
tan(%X) Calculate the tangent of X
tan(45) = 1.61978
Cosecant
csc(%X) Calculate the cosecant of X
csc(30) = 1.01211
Cotangent
cot(%X) Calculate the cotangent of X
cot(80) = 0.11107
Secant
sec(%X) Calculate the secant of X
sec(60) = -1.04996
Mathematical functions can be combined using brackets.
Mathematical functions can be combined using brackets. Where mathematical calculations are being performed you should observe correct usage of brackets, otherwise the calculation will be read left to right.
Use within an expression to compare or transform dates.
These functions allow you to:
Retrieve the current date/time
Get an index for a given date
Add or subtract from a date
Calculate the difference between dates
Compare two dates to determine if one is in the past, present or future from the other
Inputs to these functions must come from a concept set to a date type. An error will be displayed if you try to use these on data that is from a string, number or truth concept.
Date format: YYYY-MM-DD
These functions may output timestamps, dates, numbers or true/false. The output data type will be mentioned for each function.
Functions to get the current date or date/time to use within other functions. For example to work out a person's age you can write an expression to calculate the number of years between a person's date-of-birth and today's date.
Data type of output: date/time
Today
today() Current date at the point the function is executed during a query. The time will default to midnight.
today() = 1703203200000 (translates to 2023-12-22 00:00:00)
Now
now() Current date and time at the point the function is executed during a query.
now() = 1703249564941 (translates to 2023-12-22 12:52:44)
Functions that take a date and return an index (number) based on the chosen function.
Data type of output: number
Day of week
dayOfWeek(%date) Returns the nth day of the week for a given date (a number from 1 to 7 where Monday = 1 and Sunday -= 7)
dayOfWeek(2023-12-22) = 5 (it's a Friday)
Day of month
dayOfMonth(%date) Returns the nth day of the month for a given date
dayOfMonth(2023-12-22) = 22
Day of year
dayOfYear(%date) Returns the nth day of the year for a given date
dayOfYear(2023-12-22) = 356
Month of year
monthOfYear(%date) Returns the nth month of the year for a given date (a number between 1-12)
monthOfYear(2023-12-22) = 12
Year
year(%date) Returns the year of a given date
year(2023-12-22) = 2023
Add or remove a number of days, weeks, months or years from a date to create a new date.
This function requires you to pass in a date followed by a number you want to add. e.g. addDays(2023-12-22, 3)
= 2023-12-25.
To subtract from a date you can use a negative number. e.g. addDays(2023-12-22, -3)
= 2023-12-19
These examples use static data, but both arguments of this function can be dynamic by using variables, so long as the data used is of the correct type. E.g. addDays(%date, %number).
Data type of output: date/time
Add days
addDays(%date, n) Add n number of days to a given date.
addDays(2023-12-22, 3) =
1703462400000 (converts to 2023-12-25)
Add weeks
addWeeks(%date, n) Add n number of weeks to a given date.
addWeeks(2023-12-22, 3) = 1705017600000 (converts to 2024-01-12)
Add months
addMonths(%date, n) Add n number of months to a given date.
addMonths(2023-12-22), 3) = 1711065600000 (converts to 2024-03-22)
Add years
addYears(%date, n) Add n number of years
addYears(2023-12-222, 3) = 1797897600000 (converts to 2026-12-22)
Returns the difference between two dates as a number.
This function requires you to pass in two dates. Regardless of the order, it will always output a positive number.
Data type of output: number
Seconds between
secondsBetween(%date1, %date2) The number of seconds between two date/times.
secondsBetween(2023-12-22 12:30:10, 2023-12-22 12:30:12) = 2
Minutes between
minutesBetween(%date1, %date2) The number of minutes between two date/times.
minutesBetween(2023-12-22 12:30:10, 2023-12-22 12:40:12) = 10
Hours between
hoursBetween(%date1, %date2) The number of hours between two dates/times.
hoursBetween(2023-12-22 12:30:10, 2023-12-22 14:30:12) = 2
Days between
daysBetween(%date1, %date2) The number of days between two date/times.
daysBetween(2023-12-18 12:30:10, 2023-12-22 12:30:12) = 4
Weeks between
weeksBetween(%date1, %date2) The number of weeksonds between two date/times.
weeksBetween(2023-11-20 12:30:10, 2023-12-22 12:30:12) = 4
Months between
monthsBetween(%date1, %date2) The number of months between two date/times.
monthsBetween(2023-10-22 12:30:10, 2023-12-22 12:30:12) = 2
Years between
yearsBetween(%date1, %date2) The number of years between two date/times.
yearsBetween(2023-12-22 12:30:10, 2025-07-18 12:30:12) = 1
Pass two dates into the function to check if one is in the past, present or future from the other.
These functions will check the dates and evaluate to true or false for the expression to either pass or fail.
Data type of output: Boolean (true/false)
Is before date
isBeforeDate(%date1, %date2) Checks if date 1 is before date 2 and returns true or false
isBeforeDate(2023-12-21, 2023-12-22) = true
Is same date
isSameDate(%date1, %date2) Checks if date 1 is the same as date 2 and returns true or false
isSameDate(2023-12-21, 2023-12-22) = false
Is after date
isAfterDate(%date1, %date2) Checks if date 1 is after date 2 and returns true or false
isAfterDate(2023-12-21, 2023-12-22) = false
Performs comparisons or transformations over a list of facts.
Count how many facts exist for a given relationship. This enables you to determine the number of relationships a specific entity has.
Data type of output: Number
countRelationshipInstances(%ACCOUNT_ID, 'has account flags', *)
In this example %ACCOUNT_ID
denotes a variable where an account identifier is used to constrain the function to consider only that account. The asterisk *
denotes all objects.
This will return the number of account flags associated with the given account. For example, if account "ACC-7823" has three flags ("Suspicious activity", "High risk", "Manual review"), the function will evaluate to 3
.
Adds all number objects from a list and returns the total, when they share the same relationship.
Data type of output: number
sumObjects(%COMPANY, ‘has employee salaries’, *)
In this example %COMPANY
denotes a variable where a company name is used to constrain the function to consider only facts for that company. The asterisk *
denotes all objects.
This will return a sum of all employee salaries for the given company.
Note: the relationship in this example must be plural
Returns the lowest value from a list of objects.
Supports finding the lowest number or earliest date.
Data type of output: date or number (depending on the input data type)
minObjects(%COMPANY, ‘has employee salaries’, *)
In this example %COMPANY
denotes a variable where a company name is used to constrain the function to consider only that company. The asterisk *
denotes all objects.
This will return the lowest salary for the given company.
Note: the relationship in this example must be plural
Returns the highest value from a list of objects.
Supports finding the highest number or latest date.
Data type of output: date or number (depending on the input data type)
maxObjects(%COMPANY, ‘has employee salaries’, *)
In this example %COMPANY
denotes a variable where a company name is used to constrain the function to consider only that company. The asterisk *
denotes all objects.
This will return the highest salary for the given company.
Note: the relationship in this example must be plural
Compares one list of instances against another list and returns either True or False if the items in the 1st list are present in the 2nd list.
Data type of output: Boolean (true/false)
Combine multiple conditions within expressions to create more complex logic. Logical operators enable you to evaluate whether multiple conditions are true or whether at least one condition is true.
Operators available:
and
: All conditions must be true for the expression to evaluate to true
or
: At least one condition must be true for the expression to evaluate to true
Examples
(includes(%POLICY_TYPE, 'Auto')) and (%CLAIM_AMOUNT > 5000)
This example evaluates to true only when both conditions are met: the policy type contains "Auto" AND the claim amount exceeds £5,000.
(%RISK_SCORE > 80) or (includes(%CLIENT_STATUS, 'VIP'))
This example evaluates to true when either condition is met: the risk score is above 80 OR the client has VIP status.
Logical operators can be combined to create more complex conditions:
((%AGE < 25) or (%DRIVING_YEARS < 3)) and (%ACCIDENT_COUNT > 0)
This will evaluate to true when either the client is under 25 OR has less than 3 years of driving experience, AND they have had at least one accident.
Truth table for logical operators
true
true
true
true
true
false
false
true
false
true
false
true
false
false
false
false
Use parentheses to control the order of evaluation when combining multiple logical operators.
and / or must be lowercase
These functions will output a unix timestamp, which is a machine readable datetime format. Mostly you will not see these timestamps. However, if you do come across them during building and want to see it in a human-friendly format there’s many websites you can use to convert them such as .