To create a crosstab report (sometimes called a "Pivot Table") in Jaspersoft's iReport Designer, simply drag a Crosstab component from the palette to a Summary band and configure through the wizard. However, if you need more than 2 row or 2 column groups in the crosstab, you'll need additional configuration.
Jaspersoft's iReport Designer features a New Crosstab wizard that will guide you through adding a Crosstab component to a report.
The wizard is limited to 2 row groups and 2 column groups. For most concise reports, this is sufficient. Too many row and column groups can be disconcerting because various totals will appear throughout the tabular data.
Row Groups
If you need additional row and column groups, add a Row Group and then build a set of totaling cells into the cross tab. This example works with the following spreadsheet. A 2 x 2 crosstab was built with Year and Region forming the initial set of rows and Dept Name and Dept ID forming the initial set of columns. This is the maximum set that can be configured using the wizard.
The spreadsheet has an additional column, "Sr. Officer", that will be added as an additional row group.
Data Supporting a Crosstab Report |
Start by right-clicking in the Report Inspector and selecting "Add Row Group".
Add a New Row Group |
Crosstab with Sr. Officer Variable Added |
The report can be previewed as this point and the data will total correctly. To add in the Sr. Officer subtotaling, components need to be added from the palette for the label (Static Text) and each of three totals: Dept ID, Department, and Total. The totaling components are Text Fields.
Crosstab with Totals Created |
Each of the three Text Fields are configured to use the same variable $V{BudgetAmount_Measure}. The type is set to java.lang.Integer.
The result is a report that includes the extra data. You may want to apply background colors to make it appear more consistent with the other table cells. (I skipped the extra formatting to make the cells stand out.)
Crosstab Report with Row Group Created Outside of Wizard |
No comments:
Post a Comment