Jump to content
Changes to the Jaspersoft community edition download ×

Print When Expression. Sum() of group > 0


javier.8

Recommended Posts

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
TOTAL 0

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.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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,

Olga

Link to comment
Share on other sites

  • 5 years later...

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...