Key Calculations
It's possible to perform calculations on data keys. This section documents the various operators and functions that are available.
Keychain Expressions
Keychains have their own expression language that is largely similar in syntax to Java. You can type in expressions within the "@" symbols to perform calculations on the keys. Here are the operators in order of precedence.
Operator |
Function |
Example |
Parenthesis |
(expr) Nested expressions |
Any portion of a Key Chain can be enclosed with parenthesis to guarantee precedence. |
Multiplicative |
*, /, % Multiply, divide, modulo |
These are the most common and intuitive operators. You might want to display @quantity*price@ in an invoice line-item or calculate a percent like this @profit/revenue*100@. |
Additive |
+, - Add, subtract |
See multiplicative above |
Relational |
>, <, >=, <= Greater-than, less-than, greater/less-than-equal |
These are most useful for conditionals: @amount>=0? "Credit" : "Debit"@ or @name=="this"? "that" : name@ |
Equality |
==, != Equal, not-equal |
See Relational above |
Logical |
AND && |
These operators make it possible to test multiple conditions: @revenue>100 && budget<50? "Winner!"@ or @name=="Jack" || name=="Sam"? "Good Name!"@. |
Logical |
OR || |
See and above |
Conditional |
? : If/then - with form "expr? true_expr : false_expr" |
Provides IF/THEN/ELSE expressions. Note: a false expression is optional. 'null' will be evaluated to false and non-null as true. You can provide null substitutions like this: @name? name : "(None provided)"@. You can also nest conditionals for more conditions. For example, @age>=21?"Adult":(age>12?"Teen":"Child")@. |
Assignments |
=, += |
For the brave, you can create temporary variables for use in a report. Most of the functionality you might use this for is covered in more intuitive ways (such as the Running key), but it is possible to define a variable in a header row: @revTotal=0@ and update it in details rows @revTotal+=revenue@. |
Math Functions
The following functions return floats.
Menu Item |
Function |
floor(float) |
Round input down to the nearest whole number. |
ceil(float) |
Round input up to the nearest whole number. |
round(float) |
Round input to the nearest whole number. |
abs(float) |
Returns the absolute value of the input (if number < 0 return number * -1). |
min(float, float) |
Returns the input number with the least value. |
max(float, float) |
Returns the input number with the greatest value. |
pow(float, float) |
Returnsfirstnumber to the second number power. |
String Functions
The following functions return strings.
Menu Item |
Function |
startsWith(String, String) |
Returns true if the first string starts with the second. |
endsWith(String, String) |
Returns true if the first string ends with the second. |
substring(String, int start) |
Returns a substring of String beginning at position start. |
join(List aList, String aKeyChain, String aDelimeter) |
Used to display an individual attribute of individual objects as a single String. Suppose you have a list of movies and want to show their titles in a comma separated list: @join(getMovies, "getTitle", ", ")@ |
substring(Object aString, int start, int end) |
Obtain a subset of a given string. This could be useful if you wanted to restrict a text field to a certain number of chars:@substring(title, 0, 10)@ |