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

Running percentage


gan

Recommended Posts

I am trying to do a report with running sums and percentage.

Using a "sum" variable and a textfield with evaluation time "now" I can have a running sum. A second textfield, eventually hidden, with evaluation time "report" would provide the total sum to each line of the report.

 

Last step, where I'm stuck, would be to set a textfield with evaluation time "now", that divide the running sum variable with the content of the hidden field (total sum).

How can I retrieve the content of a textfield from another one?

 

The report would look like something like:

 

Item Val RunSum RunPerc

----- --- ------ -------

Item1 10 10 25%

Item2 10 20 50%

Item3 20 40 100%

----- --- ------ -------

 

Thanks in advance to all contributors.

Giovanni

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello,

 

You must seperate yourself from the philosophy that text fields and fields are coupled. In fact, they are completely different. iReport supports building RHS (right hand side) expressions in java, so open the proprties of your text field, go to the text field tab, and you will have access to the expression builder, as well as a simply text box to write your expression.

 

Also, there's no ~reason~ to create a hidden field, simply create a variable that will do your running sum, and total sum - if you

 

I'll provide some psuedo code because I don't know the Java types of the variables you're trying to divide:

 

$V{runningSum}.intValue() / $V{totalSum).intValue()

 

Depending on the Type of your display field, and which JRE you're using, you will have to modify that expression to compile under the version of java you're using.

Link to comment
Share on other sites

Schaibaa,

I agree on the fact that texfields and variables are different entities.

The point is that the variable is the same (a "sum" variable on a field), just evaluated (computed) at different times: "now" for running sum, "report" for total. To my knowledge, "evaluation time" can be done only with textfield, so here is where I am stuck, since I can't choose two different evaluation time for the same variable, in a formula.

 

But maybe I am on a wrong track and there is a different solution for my running percentage request. I just can't figure it out right now...

Link to comment
Share on other sites

Ok, I understand what you mean a bit more now.

 

Create a new variable to only hold the sum.

Make it identical to your other one.

 

Varibales do have reset types:

 

None: The Initial Value Expression is always ignored

Report: The variable is initialized only once at the beginning of report creation by using the Initial Value Expression

Page: The variable is initialized again in each new page

Column: The variable is initialized again in each new column (or in each page if the report is composed by only one column)

Group: The variable is initialized again in each new group (the group specified in Reset Group)

 

So if you make the reset type to none, and make it sum up all of them, you use that seperate variable you created for your calculations.

Link to comment
Share on other sites

Does not work.

I tried to display the variable on a dedicated textfield to verify its behaviour, what I get is the double of the field value. The textfield is evaluated "now", the variable is reset to "none".

:S

Link to comment
Share on other sites

Then you're expression is incorrect. It's just Java, whatever that variable is evaluating, is evaluating to double what you expect it to. If you can't figure it out, and it's ALWAYS double, just divide it by two.

 

 

I'm not exactly sure how your report is setup, but one thing you may consider trying, is change the variable calculation type to "Sum" and in your variable expression, enter the other variable (the line sum's, or whatever they are). Set the reset type to none, etc.

Post edited by: schaibaa, at: 2007/03/15 17:24

Link to comment
Share on other sites

Well, I would have expected a total for the column, not the double of the current line.

 

The tricky point with running percentage is that I need the same "sum" variable computed twice: "now" and "report". The first instance will return the running sum, the second the total sum.

 

I still don't have a solution for it.

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