iReport Development

Expanding a Cross tab in iReport Designer

 

To create a cross tab report (sometimes called a “Pivot Table”) in iReport Designer, simply drag a Cross tab 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.

iReport Designer features a New Crosstab wizard that will guide you through adding a Cross tab 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.

 

excel0412

Data Supporting a Crosstab Report

Start by right-clicking in the Report Inspector and selecting “Add Row Group”.

addrow

Add a New Row Group

The new row group will appear in the report’s Cross tab tab.

Crosstab tab

Cross tab with Sr. Officer Variable Added

 

Total

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.

 

Static Text

 

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

 

stand out

 

Cross tab Report with Row Group Created Outside of Wizard

Most cross tab reports can be rendered using 2 row groups.  Jaspersoft’s iReport Designer provides a convenient wizard walking you through crosstab creation.  If you need more row groups, add them manually then add extra components from the palette for the totals.

 

Print Friendly

Leave a Reply