Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JasperReports counter variable always incrementing

This should be a simple question on JasperReports. I'm trying to do a simple counter over the whole report that should increment based on a condition. However, whatever I try, it seems like the counter variable is always being incremented, regardless of the variable expression. My variable's definition properties are below:

Class: Integer
Calculation: Count
Reset type: Report
Increment type: None
Variable Expression: $F{on_target}.doubleValue() >= 0.0
Initial Value: Integer.valueOf(0)

I have a total of 23 rows in the data set, and based on the criteria, the counter should eventually equal 18. I have the variable outputting in the Summary band, with Evaluation Time to Now. However, regardless of the evaluation time, and even setting the Variable Expression to Boolean.valueOf(true == false), the variable's value always ends up as 23.

What simple little thing am I forgetting?

like image 441
Scott Balmos Avatar asked Aug 18 '11 21:08

Scott Balmos


People also ask

How do you increment a variable in Jasper report?

Increment TypeNone - The variable is incremented with every record during the iteration through the data source. Report - The variable never gets incremented during the report filling process. Page - The variable is incremented with each new page. Column - The variable is incremented with each new column.

How do I set parameter value in Jasper report?

To add a parameter to a Jasper Report using Jaspersoft Studio it is an easy task. Into the Jaspersoft Studio right click on "Parameters" and choose "Create Parameter". Now you can use that report using a parameter. This parameter will be passed when the report will be called from Java for instance.

How do I set parameters in iReport?

Parameters promptDrag the parameter from the report inspector inside the title band. iReport creates a textfield to display the parameter value. Run the report using an empty data source by clicking the preview button. The parameter prompt dialog will appear asking for a value for the MESSAGE parameter.

How do I pass parameters in Jasper studio?

To pass parameters from the Main report to the datasets, the parameters have to have the same name. That is, if the name of the parameter in the main report is 'Region', then the Datasets which need this parameter will have to have a parameter with an identical name.


1 Answers

I think I've got it. This makes vaguely no sense, but... (mind you, this is my first time working with Jasper Variables, so it was trial and error).

The Variable Expression isn't quite a Boolean, where a counter type variable isn't incremented if the expression is false, like you'd think. The variable is incremented if there is any value evaluated in the expression. Thus, for me, what ended up working is below:

$F{on_target} >= 0 ? 1 : null

Note the usage of null if the expression should be false.

It makes vague, twisted sense. But is in no way intuitive. Oh well, so it goes...

or in other words:

When you are using the Calculation:Count function of a Jasper-defined Variable you want the Variable Expression to:

  • resolve to non-null value to increment the counter
  • resolve to a null value if you do not want to increment the counter

That's why the test listed above works

like image 80
Scott Balmos Avatar answered Sep 21 '22 02:09

Scott Balmos