Background
The Totals section in the image below shows strange results for the Trend column. The text should be true when the value under the column named Previous equals the value under the column named Current.
Print When Expression & Text Field Expression
The expressions are evaluated using identical code:
new java.lang.Boolean(
$V{LAST_WEEK_TALLY_0}.add(
$V{LAST_WEEK_TALLY_1} ).add(
$V{LAST_WEEK_TALLY_2} ).add(
$V{LAST_WEEK_TALLY_3} ).longValue() ==
$V{THIS_WEEK_TALLY_0}.add(
$V{THIS_WEEK_TALLY_1} ).add(
$V{THIS_WEEK_TALLY_2} ).add(
$V{THIS_WEEK_TALLY_3} ).longValue()
)
The Evalutation Time for the Text Field is set to Band.
Problem
It appears as though the Print When Expression code is being evaluated for the values under the Previous and Current columns one row too late. The value being printed is correct for that row. This means that the evaluation ti开发者_如何学Pythonme for Print When Expression and Text Field Expression are not evaluating at the same time.
Question
What do I need to do to make Print When Expression and Text Field Expression evaluate to the same result at the same time? This would then produce the word true for the Totals' Trend column whenever Previous == Current
.
I have two suggestions, not sure if either will work:
1. Using summation from iReport
Assuming you are using cross table, there is a feature to sum the total on the row or on the column. Make Previous Total, equal to the number of Previous Totals, and same goes for Current Total.
Then in Trend column, write an expression like Current_Value - Previous_value ==0
2. Find the sums in Query
This is the more robust solution, maybe a little more complicated though. I usually don't rely much on iReport, and always give it ready data.
If you generate your report data in Java, it will be easy to fill in all the values before calling the report.
An inelegant, but functional solution is to merge the static text fields together, and avoid having to synchronize Print When Expression and Text Field Expression in favour of just the latter.
($V{LAST_WEEK_TALLY_0}.add(
$V{LAST_WEEK_TALLY_1} ).add(
$V{LAST_WEEK_TALLY_2} ).add(
$V{LAST_WEEK_TALLY_3} ).longValue() ==
$V{THIS_WEEK_TALLY_0}.add(
$V{THIS_WEEK_TALLY_1} ).add(
$V{THIS_WEEK_TALLY_2} ).add(
$V{THIS_WEEK_TALLY_3} ).longValue()) ? "-" :
($V{LAST_WEEK_TALLY_0}.add(
$V{LAST_WEEK_TALLY_1} ).add(
$V{LAST_WEEK_TALLY_2} ).add(
$V{LAST_WEEK_TALLY_3} ).longValue() <
$V{THIS_WEEK_TALLY_0}.add(
$V{THIS_WEEK_TALLY_1} ).add(
$V{THIS_WEEK_TALLY_2} ).add(
$V{THIS_WEEK_TALLY_3} ).longValue()) ? "Up" : "Down"
精彩评论