Print When Expression. Sum() of group > 0

Hello Everyone.

Here's my problem. I have a report with a simple group. If the sum() of the price column of that group equals 0, I should not display that entire group.

I made you an example. The group name is SERVICE. The Rows beginning with "Service:" are group headers. The rows beginning with "Total" are group footers.

Service: Transportation
Item 13122 10.60
Item 13434 20.50
TOTAL 31.10
Service: Handling
Item 6579 35.7
Item 7256 -35.7

What I need to do is NOT TO SHOW the header, footer and the items of the Handling Service, as the total for that service is 0. The main problem is that the SUM function in jasper is not actually a function, but rather a variable being accumulated as the report rows are being fetched. But at the time of the "print when expression" this variable is not yet accumulated. So when the print when expression is being evaluated It hides everything, even the Transportation service group (because that variable is reset to 0 at the beginning of the group). I've been searching the web all morning, and I can't find the answer.

To make my question formal: How do I use the "print when expression" of a group based on the sum() of a field of that same group? In this case, how do I hide the groups in which the group total is 0?

Thank you very much in advance.

javier.8's picture
Joined: Apr 5 2013 - 8:35am
Last seen: 1 year 1 month ago

2 Answers:

Hi Javier,

you should set evaluatoin time for the content(Service:Transportation Text Field) to Group and apply print when experssion to those Text Fields.  I that case, if you would have some non-empty content, it should be displayed. But when it's empty, some space will be reserver.

Alternatively, you can create Subreport for that group header, and then size it to 0 in any condition in the parent report as well as the Group Header band height. It will stretch to the content when necessary.

Hope it helps,


oesina's picture
Joined: Jun 20 2011 - 10:27am
Last seen: 10 years 2 months ago

From what I understand, printWhen expressions are always evaluated NOW, and cannot be changed. In my case, my printWhen expression was based off the first row of my data, and didn't consider the rest of it. The only workaround I could find was to compute my totals in SQL and stop relying on Jasper to make decisions whenever possible.

adavenport's picture
Joined: Feb 21 2019 - 8:09am
Last seen: 1 year 11 months ago