Jump to content

Can I do a Sum of Percentages?


tmagalhaes

Recommended Posts

Im trying to migrate a report to Jasper Report.

There is one issue I'm having with this migration.

The attached picture illustrates the problem.

I have 3 columns:

The first total is a reference to a field in my query.
The second total is the percentage of the first field's value over the sum of all values in that field. I got this second column working by using a report field with Evaluation time = Auto and dividing the field value by the variable used to show the gross total.
The expression ended up something like ($F{"Foo"} / $V{"SumOfFoo"})

Now comes the problem, that 3rd column.
This column shows the running sum of the calculated percentages.

Since these kind of Percentages can't be done at the "data model level" in Jasper and must be deferred to the "presentation level" I can't do a Sum of the calculated percentages.

I though about calculating this new column without depending on the values on the middle column, but expression would be something like ($V{"SumOfFoo"} / $V{"SumOfFoo"} with the first having evaluation time now and the second evaluation time group. But of course, I can't set different evaluation times for each part of the expression. Setting it to Auto would of course always give me 100%.

So, is this even possible?
Thanks for your time in reading this.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

It is possible, but a little tricky.

You will have to create an additional variable that has resetType="None" and copies the SumOfFoo value.  Then use $V{NewVar} / $V{SumOfFoo} in a text field with evaluationTime="Auto".  The new variable will be evaluated immediately due to its reset type.

Regards,

Lucian

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