Monday, 6 February 2012

NextReports: Variables, Functions & Expressions

NextReports has a simpler way of working with data, than other reporting solutions.

For example, inside iReport for JasperReports you can define a so-called variable just to use it in another fields. The problem with this approach is that the user must specify when this variable must be evaluated and when to be reset. (like page, report, group, column types). This is no easy task for non-business users who want to create some reports. This also can bring some invalid calculations if the user does not understand what he is doing.

NextReports does not have user-defined variables. In NextReports Variables are just application-defined like ROW, GROUP_ROW, PAGE_NO and so on.

Instead, users can create Expressions and Functions. Expressions can contain text, variables, parameters, columns and functions (from version 5.1). Functions can be any of SUM, AVERAGE, MIN, MAX, COUNT, COUNT DISTINCT and can be done on sql column or on expression.

For NextReports a field is evaluated if it is found inside layout. So, users do not need to ask themselves when to evaluate something. If you need an expression just to compute something without showing the result, you can make it hidden. But, you will always know when the expression is evaluated without asking yourself.

If we have two functions inside a group footer band

$F{SUM(HOURS)} : computes the sum of hours for a project (work, travel, administration, meeting)
$F{SUM(WORKHOURS)} : computes the sum of implementation hours

and we want also to see how much implementation represents in percentage, it is very easy to create an expression. From version 5.1 the user can select the functions found in the current band, in this case $F{SUM(HOURS)} and $F{SUM(WORKHOURS)}.


Report layout will show the defined expression:


Because functions are interpreted as double values the division will create a double. If you have an integer column $C_HOURS for example and you want to use div operations, be sure to convert it to double like $C_Hours.doubleValue(), otherwise the result will be an integer.


Result can be formatted with pattern property like in following exported pdf:



1 comment:

  1. Great and excellent article. I got more knowledge from this article.recognition a lot for sharing this feature with us
    Python Online Training
    Learn Python Online

    ReplyDelete