I have a problem with JasperReports. I want to group the records depending on one specific column's value.
For example input data:
Name--email--PledgeType--amount
aaa--aa@yahoo.com--1--20.00
bbb--bb@yahoo.com--2--30.00
ccc--cc@gmai.com--1--35.00
ddd--dd@gmai.com--2-- 40.00
The output report will be grouped by the "PledgeType" value (1, 2, ... number):
Total for group one: 55.00
Name email amount
aaa aa@yahoo.com 20.00
ccc cc@gmai.com 35.00
------------------------------------
Total for group two: 70.00
Name email amount
bbb bb@yahoo.com 30.00
ddd dd@gmai.com 40.00
Can JasperReports solve this problem? how?
You can define grouping in JasperReports. JasperReports calculates the total for you, there is comfortable way to add groups and totals. Here an overview what you need to do in iReport.
To add the group
To add the total
$F{amount}
."Total for group " + $F{PledgeType} + ": " + $V{totalPledge}
, Expression Class:java.lang.String
. Evaluation time: Group. Evaluation Group: PledgeType.Info: The evaluation time decides when a variable gets evaluated, i.e. when the sum of the calculation will be shown. If you set it to group it means 'once the group processing is completed'.
Attached the generated report and the JRXML.
The JRXML is created with iReport 5.0 - however, if you follow the steps above it should work with JR v 2+