Functions
- Former user (Deleted)
- Zoe Baldwin
- Adam Campbell
Overview
Attribute functions are used for performing calculations on data in PhixFlow. The most common uses are:
- populating output attributes;
- building filters.
This page explains the concepts you need to understand how functions work in PhixFlow. The concepts are should be fairly straightforward for anyone used to using Excel, or any type of database. However, it is important to understand them before writing the complex transformations that you can achieve using functions in PhixFlow.
Expression editors display symbols to indicate whether they are expecting PhixScript or Embedded PhixScript. PhixScript Embedded PhixScript
See Embedded Expressions and Expressions and PhixScripts.
Terminology and Conventions
In examples in the following descriptions, functions are given as out.calls = ifNull(in.numCalls, 0, 1). In this format, there are three sections of each expression:
- The first part of the example - out.calls - is either the output attribute name or an input attribute name (for an input filter).
- The middle part of the example - = - is the operator that links the two main parts of the expression. In a filter this can take a number of value, e.g. >, >=, contains. For an output attribute function this is always =, that is, that output attribute is set to the resulting value of the function on the right hand side.
- The final part of the example - ifNull(in.numCalls, 0, 1) – is the function itself.
Where a function can take, as one of its arguments, a list of values this is expressed in square brackets, e.g.:
function([value1, value2, ...])
See Arrays and Record Sets for details of how lists are handled in functions. Such a list is often called a vector. Indexes: always start at 1. Many functions return an index, indicating the position in a list at which a matched value has been found. E.g. see getElement.
Data Types
Functions can take the following data types:
- float: a floating point number
- integer: an integer
- string: a string
- date: there is no actual date type is PhixFlow; dates are handled as string, but these must have a particular format, either:
- "yyyymmdd.hhmmss", or
- "yyyymmdd".
Lists of Values
Where a function can take a list of values as one of its arguments, the argument will often be an attribute of an input table, or an expression based on an attribute of an input table. For example: sum(in.value) where in is an alias for an input table containing the numeric attribute value. When used as part of a merge or aggregate function, for example, the argument in.value will resolve to a list of values - all the values of value associated with a particular key combination. The following relational operators are available: The following arithmetic operators are available:Expression Operators
Responsive Functions
To improve performance, a sub-set of functions, listed below, can be evaluated by the client rather than the server. These are useful where you want an expression to be evaluated quickly, for example in formatting rules.
If an expression includes only the following, client-calculated functions, the whole expression is evaluated on the client. For any other function, the expression is evaluated on the server.
Functions that can be evaluated on the client:
And Contains CountElements Do Dot (e.g. _form.UID) Divide Equals = Excluded Greater than | Greater than or equals If IfNull IsEmpty IsNull Less than Less than or equals ListContains Minus Multiply | Not Not equals Now Or Plus Switch Today Try |