Example expressions
These examples show common patterns you can adapt when you build an expression. Each one says what it returns, so you can check where you can use it. The FastStats expression reference describes each function.
Note
The variable names in these examples, such as [DOB] and [Appeal], may not exist in your system. Replace each one with the exact name of a variable in your own FastStats system. Otherwise, Orbit shows an error such as Variable 'Lastname' not found.
Dates
Date functions work out ages, months, and time between dates. See the FastStats date functions.
Age
Work out each supporter's age in years from their date of birth:
Returns a number, such as 34. Use it to filter supporters by age, or in message personalisation to target milestone birthdays or adjust images for different age groups.
Birthday month
Work out the month of each supporter's birthday, from 1 for January to 12 for December:
Returns a number, such as 3 for March. Use it as a filter to send birthday messages to everyone with a birthday in the coming month.
Time since a first gift
Work out how many years have passed since each supporter's first gift:
Returns a number of years, such as 7. Use it to celebrate anniversaries of a supporter's first gift, or to thank long-standing supporters.
Locations
Location functions work out distances from UK postcodes, in miles. See the FastStats location functions.
Distance to a location
Work out the distance from each supporter's postcode to one location, such as your head office:
Returns a number of miles, such as 82.05. As the measure on a cube tile with a Region dimension, the Mean function shows the average distance for each region.
Distance to the nearest location
Work out the distance from each supporter's postcode to the nearest of several locations, such as your regional offices or shops:
Returns a number of miles to the nearest location. Filter on it to find supporters within 20 miles of their nearest office.
Text
Text functions join and tidy text. The If examples under Conditions also search text, with StrContains. See the FastStats string functions.
Personalised greeting
Join text and variables into a greeting:
Returns text, such as Dear Mrs J Smith. Use it as a content field in message personalisation, or as a data grid column for a mailing export.
Tidy capital letters
Capitalise the first letter of each word, for names that were entered in lower case:
Returns text, such as Sarah for sarah. Use it in a greeting, so names look right in your messages.
Numbers
Maths functions round and calculate numbers. See the FastStats maths functions.
Suggested gift amount
Suggest a gift 20% higher than each supporter's last gift, rounded to the nearest £5:
Returns a number, such as 60 for a last gift of £50. Use it in message personalisation to ask for an amount that suits each supporter.
Conditions
Conditions return different values for different supporters. These examples use the FastStats logical functions, missing value functions, and selector functions.
Check an email address
Check whether each supporter's email address is in a valid format:
Returns 1 for a valid format and 0 for an invalid one. Filter on 1 to leave out badly formatted addresses before an email campaign.
Flag missing values
Flag supporters who have no date of birth recorded:
Returns text: Unknown or Known. Use it as a data grid column to check your data before an age-based campaign.
Simple If statement
An If statement returns one value when a condition is true and another when it's false. This one returns 1 for supporters whose segment code contains Y or Z, and 0 for everyone else:
Returns 1 or 0. Use it for basic segmentation, or as a flag for reporting.
If statement with text values
An If statement can return text as well as numbers. This one asks supporters whose last gift was £50 or more for £75, and everyone else for £40:
Returns text: £75 or £40. Use it in message personalisation to set the ask in an appeal.
If statement with two conditions
Combine conditions with And or Or. This one returns 1 for supporters who gave to the emergency appeal and have agreed to email or SMS contact:
If(And(DescOf([Appeal])="Emergency",StrContains(CodeOf([ContactPermissions]),"EM", "SMS")),1,0)
Returns 1 or 0. Use it to target a follow-up to a specific group of donors.
If statement with an exclusion
Combine conditions with Not to include some supporters and exclude others. And can take any number of conditions. This one returns 1 for supporters in segment Y or Z who gave to the emergency appeal, but haven't agreed to email or SMS contact:
If(And(StrContains(CodeOf([Segment]),"Y", "Z"), DescOf([Appeal])="Emergency", Not(StrContains(CodeOf([ContactPermissions]),"EM", "SMS"))),1,0)
Returns 1 or 0. Use it to find gaps, such as engaged donors you can only reach by post.
Several bands with Case
When you need more than two outcomes, Case is easier to read than nested If statements. It takes pairs of a condition and the value to return when that condition is true. This one sorts supporters into tiers by their total giving:
Case( [TotalGiven] >= 1000, "Major donor",
And([TotalGiven] >= 100, [TotalGiven] < 1000), "Mid-level donor",
[TotalGiven] < 100, "Regular donor")
Returns text, such as Mid-level donor. Use it as a data grid column, or in message personalisation to vary a message by tier.