Jasper Report Crosstab Tutorial
A Crosstab (Cross Tabulation) is used to summarize data in a spreadsheet-like grid, where both rows and columns are dynamic. It is commonly used for aggregate reports, like sales by region and year.
Structure of a Crosstab
A crosstab consists of:
- Row Groups: Fields that define the rows (e.g., Region).
- Column Groups: Fields that define the columns (e.g., Year).
- Measures: The data to be aggregated (e.g., Total Sales), calculated at the intersection of rows and columns.
Creating a Crosstab
- Drag the Crosstab element from the Palette to the report (usually Summary band).
- The Crosstab Wizard will appear.
- Select the Main Dataset or a Sub Dataset.
- Row Group: Select the field to group rows by (e.g., `Product Name`).
- Column Group: Select the field to group columns by (e.g., `Month`).
- Measure: Select the field to calculate (e.g., `Quantity`) and the function (e.g., `Sum`, `Count`).
Handling Null Values
You can configure how to handle null values in cells.
Select the cell text field, go to Properties, and check "Blank When Null" to hide nulls,
or use an expression like $V{MEASURE} == null ? 0 : $V{MEASURE} to display a default value.