Collections
Using Collections to dynamically query large data sets
Last updated
Using Collections to dynamically query large data sets
Last updated
Collections are similar to what Excel users would called a Lookup, and you'll use them to extract variables from large datasets based on the inputs you’ve already been given.
For example, using a collection, you'd look down the first column of a dataset to find your key in a series of ABI codes, and you might then pick one particular rating from a larger table.
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
The output must resolve to a value (e.g. number, string, boolean, date). Collection queries must start with the word 'collection'.
The input value is wrapped in {{ }}
.
For example, if the input is called customer_age
and is equal to 30 in the quote, then:
count()
Counts the number of items in an response. It can be used after a filter has been applied.
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
min(), max(), mean(), range(), sum()
Finding the min number, max number, mean number, sum number and range between the two.
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
map()
Returns an array of the selected column within a collection of items. You can not return an array but you can have it as a chained step to do work on a collection.
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
filter()
Returns a filtered collection based on a columns criteria.
Filters will work on columns with strings, booleans and numbers. Filters can be chained.
You can also filter against value or empty/null data with the ~ flag
Example:
name | age | is_male | surname |
---|---|---|---|
bob | 30 | true | brown |
sue | 24 | false | |
jack | 40 | true | brown |
unique
Returns an array of the unique items from a column
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
first, last
Returns an first or last element of an array as a value. This is a common way to resolve a result.
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
exists
Checks if property value exists i.e. not null, undefined, empty string or 0.
Example:
name | age | is_male |
---|---|---|
bob | 30 | true |
sue | 24 | false |
jack | 40 | true |
date, age
If property is a date, then you can use date() to find a hour, date, month or year from the date string, or use age() to find the age since now in hours, days, months or years.
You can format a date from US or UK date formats.
Example:
name | dob | is_male | dob_format |
---|---|---|---|
bob | 1993-12-12 | true | 12/12/1993 |
sue | 1999-01-01 | false | 01/01/1999 |
jack | 1983-11-11 | true | 11/11/1983 |
A second argument can be provided to point at a date in the object instead of using now.
Date and age work with arrays.
postcode
If property is a string postcode, then you can find the area and sector.
Example:
name | dob | postcode |
---|---|---|
bob | 1993-12-12 | SW1A1AA |
sue | 1999-01-01 | L201AR |
jack | 1983-11-11 | M123RT |
regex
If property is a string, then you can use regex() to parse a regular expression against the string and return the first match.
Example: