Formula Editor

The formula editor is where you write the formula's actual mathematical expressions and computations. You can find the formula editor at the bottom of the “Add/Edit formula step” form.

For example, based on the data a client inserts as their KYC, the formula editor applies a calculation to return data such as the net income of a loan applicant or the age limit for a contract or the insurance premium for a policy. You can also test your formula before activating it. For more information about running tests, see Define Formula Expressions.

Syntax

In the editor, insert your formula expression based on a mathematical syntax comprised of the formula body and a call for calculation (the returned result). IntelliSense is available for quick selection of definitions and to provide additional information (such as properties and attributes) about the selected item.

IMPORTANT!  
When writing a formula, make sure the calculations match the step you are on, because the result may be used as input in the subsequent steps.

Use the following syntax in the formula editor to define a formula output:

Copy
result = <formula expression>;
 

You can include multi-line C# code in the formula expression, as long as you assign a result value:

Copy
var a = 1;
var b = 2;
result = a + b;
 

The usual operator precedence for operations such as addition “+”, substraction “-“, multiplication “*” and division “/” is enforced and you can further control this by using parantheses () or by splitting your computation in multiple steps.

Formulas can be of the following types:

  • constant: f = sum(1,n)
  • linear: f(x) = 2*x+1 , where x = 1,100
  • 2-dimensional: f(x,y) = x*y+30;
  • n-dimensional etc.
  • recursive: f(x) = f(x-1)+20.

Formula Arguments

Primary formula arguments are defined in the formula input (see Define Formula Inputs). For example, if you defined an argument called days in the formula input, you can create a formula step called years to convert the number of days into years with the following expression:

Copy
result = days / 365;

You can also use previous steps' outputs as arguments for subsequent step inputs. For example, after the above step, you can create a step that calculates an interest by multiplying the principal and rate input parameters with the years result from the previous step:

Copy
result = principal * rate * years

Static Collections Definitions

For collection outputs that use a Normal calculation type, you need to assign each collection item explicitly to the result value. For each data type, there is a dedicated constructor method that allows you to instantiate collection items:

Output Sub-Type Constructor Method
Text
Copy
FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.StringVector
 

E.g.:

Copy
result = new FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.StringVector("some text", "some more text", "lorem ipsum");
Whole Number
Copy
FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.DecimalVector
 

or

Copy
FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.Vector<int>
Decimal
Copy
FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.DecimalVector
Date Time
Copy
FintechOS.Metadata.Core.Workflow.Common.Formulas.DataTypes.DateTimeVector
Object
Copy
FTOS.FormulaEngine.Internal.DataTypes.ObjectVector<dynamic>(output)
 

E.g.:

Copy
var item1 = new {name = "cheap item" , price = 12.5};
var item2 = new {name = "expensive item" , price = 29.99};
result = new FTOS.FormulaEngine.Internal.DataTypes.ObjectVector<dynamic>(item1, item2);

Dynamic Collections Definitions

For collection outputs that use an Iteration calculation type, you must provide a generic formula that defines the value of a collection item in relation to the iteration counter specified in the Number of Iterations field (for details, see Add steps to a formula).

Copy
result[i] = <formula expression>;
 

For example, if based on a collection of item prices called Values (either an input argument or an output from a prior step), you wish to generate a collection of objects that pair together item numbers with their corresponding prices, you can use the following step formula:

Copy
result[i] = new {Name = "Item" + i, Price = Values[i]};
NOTE  
To make sure that the number of items matches the number of prices, set the number of iterations to Values.

Recursive formula definitions are also supported. For example, to generate a collection with the first x numbers in the Fibonacci sequence, use a whole number input argument called x for the number of iterations (make sure x is greater than or equal to 2) and use the following formula expression:

Copy
result[0] = 1;
result[1] = 1;
result[i] = result[i-1] + result[i-2];

IntelliSense Support

Pressing Ctrl+Space will launch the IntelliSense that can help you learn more about the formula you are editing, keep track of parameters you’re typing, add calls to functions and various information with only a few keystrokes.

HINT  
Already pre-defined Steps also appear in IntelliSense since they can be called in any subsequent step.

Built-in Functions

You can include the following built-in functions in your formula expressions:

Function Description Example Result
SUM(Vector) Adds all items in a collection of whole numbers or decimals. SUM(myArray) 6
ABS(Number) It returns the absolute value of the number. ABS(-3) 3
POWER(Number, Exponent) Calculates how many times to use the number in a multiplication. POWER(10,3) 1000
ODD(Number) Specifies if the number is odd. ODD(12) false
EVEN(Number) Specifies if the number is even. EVEN(26) true
TRUNC(Number) Truncates the number to a specified number of decimal places. TRUNC(17.51) 17
ROUND(Number, Precision) Rounds the number to the specified number of digits. ROUND(17.51) 18
ROUNDUP(Number) Rounds the number upward to the specified number of digits. ROUNDUP(-0.6) 0
ROUNDDOWN(Number) Rounds the number downward to the specified number of digits. ROUNDDOWN(1.9) 1
FLOOR(Number) Receives one parameter and rounds the number down. FLOOR(6.7) 6
IIF(Condition, TrueExpression, FalseExpression) IF function is a "conditional function" because it returns a value based on the condition that you specify.    
COUNT(Vector) Returns the number of numerical values (numbers and dates) in the list of arguments.    
COUNTIF(Vector, FilterExpression) Counts the number of cells within the range that meet the specified criteria.    
MIN(Collection) Returns the minimum value from an input parameter of type collection (whole number or decimal).
If the desired parameters are not available in a formula input, create your input as follows:
Copy
var a = new decimal[] {100, 25, 3};
result = MIN(a)
NOTE  
The code above may be tagged as incorrect by IntelliSense, however it is valid.
MIN(new decimal[] {100, 25, 3}) 3
MAX(Collection) Returns the maximum value from an input parameter of type collection (whole number or decimal).
If the desired parameters are not available in a formula input, create your input as follows:
Copy
var a = new decimal[] {100, 25, 3};
result = MAX(a)
NOTE  
The code above may be tagged as incorrect by IntelliSense, however it is valid.
MAX(new decimal[] {100, 25, 3}) 100
AVERAGE(Number1, Number2, Number3, …) Returns the average of the arguments. AVERAGE(1234,67543,5752) 24843
AVERAGE(Vector) Returns the average of the arguments in a collection.
Copy
var a = new decimal[] {0, 25, 50};
result = AVERAGE(a)
25
SUMIF(Vector, FilterExpression) Adds up the cells in a specified range that meet a certain condition. SUMIF can evaluate only a single criteria.

“it” is a mandatory term, standing for “item” of an array, for all Filter Expressions in all formulas which evaluate an expression.
   
SELECT(Vector, TransformExpression)   SELECT (IncomeList, it * Database (''IncomeAdjuster''))  
RANGE(Vector, RangeOperators) Navigate inside an array
Copy
var myRange = new decimal[] {1,2,3,4,5,6};
result = RANGE(myArray,SKIP(2)])

RANGE([1,2,3,4,5,6],SKIP(2)])

VECTOR(3,4,5,6)
SKIP(Number) Combined with RANGE function, you can skip an item of an array, in case for example you would like to add all items except the 3rd one in the array.

   
TAKE(Number) Combined with RANGE function, you can take as many array items as indicated by the input parameter.    
RATE (nper, pmt, pv, [fv], [type], [guess]) Returns the interest rate per period of an annuity. You can use RATE to calculate the periodic interest rate, then multiply as required to derive the annual interest rate.
Arguments:
  • nper - The total number of payment periods.
  • pmt - The payment made each period.
  • pv - The present value, or total value of all loan payments now.
  • fv - [optional] The future value, or desired cash balance after last payment. Default is 0.
  • type - [optional] When payments are due. 0 = end of period. 1 = beginning of period. Default is 0.
  • guess - [optional] Your guess on the rate. Default is 10%.
RATE(36, 150, -5000) 0.42
PMT (rate, nper, pv, [fv], [type]) Calculates the payment for a loan based on constant payments and a constant interest rate.
Arguments:
  • rate - The interest rate for a loan.
  • nper - The total number of payments for a loan.
  • pv - The present value, or the total amount that a series of future payments is worth now; also known as the principal.
  • fv - [optional] The future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
  • type - [optional] Indicates when payments are due:
  • 0 or omitted - at the end of the period
  • 1 - at the beginning of the period
A 3-year (36 months) loan for 10000 USD at 8% interest rate:
PMT(0.08/12, 36, 10000)
-313.36

Examples

For Simple types

 

For Collection Types

For Simple Collections types

 

Formula Built-in Excel Functions

Formula Built-in DateTime Functions

Data Set Calls

To extract value mappings from data sets (see Data Sets for details), use the following syntax:

Copy
DataSet("<data set name>", ("<discriminant 1 name>", <discriminant 1 value>), ("<discriminant 2 name>", <discriminant 2 value>) ... )

If all the discriminants are given as a parameter, the result will be a value. However, if one of the discriminants is not sent as a parameter, the result will be an array.

IMPORTANT!  
You can only call data sets that are active. For details, see Data Set Versioning.