Column Totals (sums)

3

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?

 

kcronin's picture
39
Joined: Oct 26 2010 - 9:31am
Last seen: 8 years 6 months ago

4 Answers:

5

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

cbarlow3's picture
1387
Joined: Mar 4 2010 - 8:59am
Last seen: 4 days 22 hours ago

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

matteusbarbosa2 - 4 years 10 months ago
-1
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.
amthomas's picture
Joined: Mar 19 2010 - 9:14pm
Last seen: 6 years 6 months ago
0

Wow, you get the awesome green + sign from me.  That worked like a charm and was exactly what I was trying to do.

Thank you for your help.

kcronin's picture
39
Joined: Oct 26 2010 - 9:31am
Last seen: 8 years 6 months ago
0

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.

Attachments: 
AttachmentSize
Image icon properties.png23.42 KB
matteusbarbosa2's picture
Joined: Jul 25 2014 - 7:51am
Last seen: 4 years 9 months ago
Feedback