Jump to content
Changes to the Jaspersoft community edition download ×

Column Totals (sums)


kcronin
Go to solution Solved by cbarlow3,

Recommended Posts

I thought this would be simple, but either it is very simple, or I am missing something.

What I am trying to do is simple: I have a column that is a BigDecimal and this column is in a group that I created within iReport.  I want the total for a group footer.

Example:
This is the group header
\/        \/                        \/
account number    Name     debt
12345                     James    40.00
12345                     Mike         55.00
Total debt: 95.00
^              ^           ^
This is the group footer

How would I be able to get the total of 95.00 through iReport itself since the debt is in a group that is based off of the account number?

 

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Create a variable called debtSubtotal (for example) and make it the same data type as $F{debt}.  Set the Calculation to 'Sum', the Reset Type to 'Group' (and pick the appropriate group from the dropdown), set the Variable Expression to $F{debt} and the Initial Value Expression to 0. 

If you also want a grand total for the report, right click the new debtSubtotal variable in the Report Inspector, choose 'Copy', then right click on 'Variables' and choose 'Paste'.  It will make a copy of the previous variable, now called 'debtSubtotal_1'.  In the Properties pane, change the name to something like debtTotal, and change the Reset type from 'Group' to 'Report'.  Leave everything else the same.

Now you can drag a copy of your $V{debtSubtotal} into your group footer band (and set the Pattern and the Horizontal Alignment appropriately) and drag a copy of your $V{debtTotal} into your Summary band.

Hope that helps.

Carl

Link to comment
Share on other sites

I am not sure what all you have done besides create a group but I will mention some things that might help.

 

You said you created a group so you have created a group. I will call this account_group.

 

This automatically creates a variable for you called account_group_COUNT as a variable but that is not what you are interested in here. You can create a new variable (account_group_SUM) for yourself under the variables.

 

In this you set these:

variable class: BigDecimal

calculation: sum

reset type: group

reset group: account_group

increment type: None (I think this is correct here)

increment group: (leave blank)

variable expression: here I think you put $V{account_group_SUM}.add($F{debt}) to add up your values. You might have to tinker with this more since I haven't messed with this in awhile.

initial value expression: BigDecimal.ZERO should work here

 

After adding that variable you should be able to put it as a field into the footer as you expect.

Link to comment
Share on other sites

  • 3 years later...

Just do it as cbarlow3 told, create a new Variable with a intuitive name, and edit its params to be like this, considering that your retrieved column is called "value", and it's type is "java.math.BigDecimal":

Variable Class: java.math.BigDecimal,

Calculation: Sum,

Reset Type: Report,

Variable Expression: $F{value},

Initial Value Expression: 0 (or whatever default value you need).

 

Link to comment
Share on other sites

Just do it as cbarlow3 told, create a new Variable with a intuitive name, and edit its params to be like this, considering that your retrieved column is called "value", and it's type is "java.math.BigDecimal":


Variable Class: java.math.BigDecimal,
Calculation: Sum,
Reset Type: Report,
Variable Expression: $F{value},
Initial Value Expression: 0 (or whatever default value you need).

A screen is attached to help you guys. Hope that it helped.

Link to comment
Share on other sites

  • 5 years later...
  • 9 months later...
  • 1 year 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...