Have any questions?
+44 1234 567 890
Appendix B. Formula language
B. Formula language
ReportServer supports the input of formulas in many places. Formula expressions are always enclosed by the character string ${}. The actual expression is placed between the curly brackets. The Unified Expression Language (EL) standardized in JSR-245 (https://www.jcp.org/en/jsr/detail?id=245 and http://www.oracle.com/technetwork/java/unifiedel-139263.html) is used here.
Simple calculations and string functions can be used in formula expressions. For example, the expression ${3 + 5} calculates the number 8. Depending on the context, different objects/substitutions are available in expressions.
In addition to the basic arithmetic operations, the following mathematical operations are implemented:
math:random() | Returns a random number between 0 and 1 |
math:sin(Double) | Calculates the sine |
math:cos(Double) | Calculates the cosine |
math:tan(Double) | Calculates the tangent |
math:abs(Double) | Returns the integer value of a number |
math:ceil(Double) | Rounds up the transferred number |
math:floor(Double) | Rounds off the transferred number |
math:round(Double) | Rounds the transferred number |
math:max(Double, Double) | Returns the larger value |
math:min(Double, Double) | Returns the smaller value |
math:pow(Double, Double) | Returns the first value to the power of the second |
math:log(Double) | Returns the natural logarithm |
math:exp(Double) | Calculated high value |
math:sqrt(Double) | Returns the root |
math:signum(Double) | Calculates the Signum function |
In addition to the methods of the Java string object, the following helper methods are available for processing character strings:
sutils:left(String, int) | Returns the first characters of the string |
sutils:right(String, int) | Returns the last characters of the string |
For conditional expressions, you can use the ternary expression operator
Bedingung ? Ausdruck, falls wahr : Ausdruck, falls falsch
to use. The following expression provides
${math:random() < 0.5 ? true : false}
returns a truth value. If the random number is less than 0.5 (this occurs in 50% of cases), TRUE is returned, otherwise false.
B.1.1 Work on Objects
If you have transferred an object via replacement, you can call methods on this object. The "today" object, for example, is available in filters or date parameters. To call a method of the object, write ${today.METHODENNAME()}. Today returns a date starting from the current date. However, if you want to select the first day of the current month, write ${today.firstDay()}. The following methods are available on the today object.
firstDay | Sets the calendar to midnight of the first day of the current month. |
lastDay | Sets the calendar to the last second of the last day of the current month. |
addDays | Moves the calendar forward/back the specified number of days. |
addMonths | Moves the calendar forward/back the specified number of months. |
addYears | Sets the calendar forward/backward by the specified number of years. |
setDay | Sets the calendar to the specified day. |
setMonth | Sets the calendar to the specified month. |
setYear | Sets the calendar to the specified year. |
clearTime | Resets the time to midnight. |
addHours | Sets the calendar forward/backward the specified number of hours. |
addMinutes | Sets the calendar forward/backward by the specified number of minutes. |
addSeconds | Sets the calendar forward/backward by the specified number of seconds. |
setHours | Sets the time to the specified hour. |
setMinutes | Sets the time to the specified minutes. |
setSeconds | Sets the time to the specified seconds. |
format | This function converts the date into a text in the specified format. This is necessary in order to make comparisons on columns that are not of the date type (see table Date format in Appendix C.). |
Example: You want to filter all invoices from the previous month. To do this, you can define the following inclusion filter:
${today.firstDay().addMonths(-1)} - ${today.firstDay().addSeconds(-1)}