Jump to content
Changes to the Jaspersoft community edition download ×

Can I sum the fields in the detail band?


joeycn

Recommended Posts

Hi all:

When I define a variable which will sum the fields in the detail band, I find that there is no increasement definition that starts with detail, it must be increased by group ????

 

I am not sure I've made myself understood. As a result, the following text is an example:

 

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

F1 F2 Group Header

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

a 1

b 5 Detail Band

c 3

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

Sum:9 Group Footer

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

 

How can i get the sum number?

Any suggestion will be appreciated!

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

If you don't specify any increment type for the variable, it will increment at each row by default. Your confusing is probably caused by the fact that this default increment type is counter-intuitively called "None".

 

You can find many examples of group total variables in the JasperReports samples. You would need to do something like

Code:

<variable name="f2GroupSum" type=".." calculation="Sum" resetType="Group" resetGroup="..">
<variableExpression>$F{F2}</variableExpression>
</variable>

 

HTH,

Lucian

Link to comment
Share on other sites

  • 2 weeks later...

I'm not an iReport expert, but this is straightforward. Say you want to sum values of the myField field. You would:

add a variable named myFieldSum. having the same (numerical) type as myField, Sum as calculation type, Report as reset type, None as increment type and $F{myField} as variable expression.

place a text field on your summary band (or on the title band with evaluation="Report") that displays $V{myFieldSum}.[/ol]

 

HTH,

Lucian

Link to comment
Share on other sites

Hello,

 

I run into the same problem. My details band consists of

3 columns, col. 0 is the party name, col. displays the votes ( $F{votes} ) of the party and col 2 should display the percentage. To calculate the percentage you need to sum up all votes e.g. $V{totalVotes}

But what I got is not the percentage but a value like

$F/{votes} / (current value of $V{totalVotes}) * 100 [%].

When I display $V{totalVotes} in the summary band it looks ok.

So the details band looks like:

Party 1 1 100%

Party 2 2 66.666%

Party 3 3 50%

Party 4 4 40%

 

Summary band:

Total 10

 

So how can one achieve that the calculation of the variable is done *before* the details band is evaluated.

BTW: the same thing happens if I want to display $V{totalVotes} in a pie chart where the value expression is the votes field. This happens even If I put the chart into the summary band.

 

Gernot

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