Appendix B. Formula Language

B. Formula Language

In many places, ReportServer supports entering formulas. Formula expressions are always enclosed by the character sequence ${}. The actual expression is placed between the curly braces. ReportServer uses the Unified Expression Language (EL) standardized in JSR-245 (https://www.jcp.org/en/jsr/detail?id=245).

In formula expressions you can use simple calculations as well as string functions. For example, the expression ${3 + 5} calculates the number 8. Depending on the context, different objects/replacements are available to you 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 absolute value of a number
math:ceil(Double) Rounds the given number up
math:floor(Double) Rounds the given number down
math:round(Double) Rounds the given 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 raised to the power of the second
math:log(Double) Returns the natural logarithm
math:exp(Double) Calculates e to the power of the given value
math:sqrt(Double) Returns the square root
math:signum(Double) Calculates the signum function

For processing strings, in addition to methods of the Java String object, the following helper methods are available:

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 operator

Condition ? expression if true : expression if false

For example, the following expression

${math:random() < 0.5 ? true : false}

returns a boolean value. If the random number is less than 0.5 (this happens in 50% of cases), TRUE is returned; otherwise FALSE is returned.

B.1.1. Working with objects

If an object is provided to you via a replacement, you can call methods on it. In filters or in date parameters, for example, the object "today" is available. To call a method of the object, write ${today.METHODNAME()}. "today" returns a date relative to the current date. 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/backward by the specified number of days.
addMonths Moves the calendar forward/backward by the specified number of months.
addYears Moves 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 Moves the calendar forward/backward by the specified number of hours.
addMinutes Moves the calendar forward/backward by the specified number of minutes.
addSeconds Moves 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 Converts the date to text in the specified format. This is necessary to perform comparisons on columns that are not of type Date (see the Date format table in Appendix C.).

Example: You want to filter all invoices from the previous month. You can define the following inclusion interval:

${today.firstDay().addMonths(-1)} - ${today.firstDay().addSeconds(-1)}