Can I sum the fields in the detail band?

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!
joeycn's picture
10
Joined: Nov 27 2006 - 9:25pm
Last seen: 16 years 10 months ago

5 Answers:

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:
<br />
<variable name="f2GroupSum" type=".." calculation="Sum" resetType="Group" resetGroup=".."><br />
  <variableExpression>$F{F2}</variableExpression><br />
</variable><br />
</td></tr></tbody></table><br />
<br />
HTH,<br />
Lucian
lucianc's picture
86885
Joined: Jul 17 2006 - 1:10am
Last seen: 3 hours 21 min ago
Hi Lucianc
I am also trying to get a variable which is updated as cumulatively. Can you give me tips how do implement using iReport? Thanks in advance.
Mortoza
mortoza's picture
1252
Joined: Oct 13 2006 - 1:42pm
Last seen: 1 year 4 months ago
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
    lucianc's picture
    86885
    Joined: Jul 17 2006 - 1:10am
    Last seen: 3 hours 21 min ago
    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
    ujbi's picture
    127
    Joined: Dec 6 2006 - 8:40pm
    Last seen: 16 years 9 months ago
    textfield evaluation time Auto fixes the problem.
    ujbi's picture
    127
    Joined: Dec 6 2006 - 8:40pm
    Last seen: 16 years 9 months ago
    Feedback
    randomness