JasperReports counter variable always increments

This should be a simple JasperReports question. I am trying to make a simple counter for the whole report, which should increase depending on the state. However, no matter what I try, it looks like the counter variable is always incremented, regardless of the expression of the variable. My variable definition properties are below:

Class: Whole
Calculation: Chart
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 be 18. I have a variable displayed in the Summary group, from Evaluation Time to Now . However, regardless of the evaluation time, and even when setting Variable Expression Boolean.valueOf(true == false) value of the variable always ends as 23.

What simple thing am I forgetting?

+7
source share
3 answers

I think I have it. It vaguely doesn't make sense, but ... (notice, this is my first experience with Jasper Variables, so it was a trial version and an error).

The Variable expression is not quite logical, where the counter type variable does not increment if the expression is false, as you think. The variable increases if there is any value in the expression. So for me, what ended up works below:

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

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

He makes a vague, twisted meaning. But this is not intuitive. Well, the way it is ...

or in other words:

When you use the Calculation: Count function of a Jasper variable, you need the Variable expression:

  • allow non-zero value increment counter
  • decide null if you don't want to increment the counter

This is why the test described above works

+4
source

Like setting a variable expression:

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

Try also setting initialValueExpression for the variable to 0.

+2
source

This worked for me:

 $F{on_target} >= 0 ? 1 : BigDecimal.ZERO 

No initial variable value is required.

+1
source

All Articles