Jump to content
We've recently updated our Privacy Statement, available here ×

Display sum in a group header


vinays84

Recommended Posts

I'd like to print the sum of values before they are displayed. For example suppose I had the query:

Code:

SELECT branch,day,sales_amt
FROM sales
WHERE branch='Toys' OR branch='Auto'

which returns :

Code:
[code]
BRANCH DAY SALES_AMT
Toys 1 200
Toys 2 300
Toys 3 400
Auto 1 100
Auto 2 200
Auto 3 300

I'd like to display

Code:
[code]
Toys 900
1 200
2 300
3 400
Auto 600
1 100
2 200
3 300

 

If I group by branch, I can create a variable which sums the sales_amt and resets for the group. The problem is the variable will only total after the last day is reached, making it possible to put the total in the group footer, but not the group header. Is there any way to achieve this?

 

Note: I cannot change the query to include the sum. I have to do it in Jasper.

 

Thanks!

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

You could create a seporate subreport that runs your query and calculates the total for your group. You could then place the subreport before the details in your group.

 

I have not found a way to evaluate a total of any sort before the details are created in the same report.

Link to comment
Share on other sites

vinays84,

 

monodude's answer is correct. The parts he put in bold are the important ones.

 

The problem in your logic was here: "The problem is the variable will only total after the last day is reached, making it possible to put the total in the group footer, but not the group header."

 

This statement can be corrected like this, "The variable will only total after the last day is reached, making it possible to put the total in the the group header only if the Evaluation Time of the field is set to Group (and the Evaluation Group is set appropriately)."

 

Leaving the Evaluation Time at its default value of "Now" will indeed cause the problems that you are running into.

 

-Matt

JasperSoft

Link to comment
Share on other sites

  • 4 years later...

I have a similar problem.  I can DISPLAY the sum in the Header if I follow the instructions given here.  In my case though, I would like to use the sum variable in an expression to determine whether or not to print a particular heading.  For instance, if the sum > 0, display a static message.  Is there a way to either use a Text Field in a "printWhenExpression" or force a variable to evaluate at the GROUP level just as the Text Field does?

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
  • 2 years later...
  • 3 years later...

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...