How to prevent joining values in Row Group (column) of Crosstab? - jasper-reports

Is there a way to unmerge cells with the same value in crosstab?
The problem is that same valued cells are getting merged.
I want the value to be repeated and have cell borders. For example, in a row group, if i have 2 columns, col1 with values 'abc' and col2 with values 1,2,3 and if there are 3 rows, the col1 is one big cell with 'abc' printed only once.
This is what I don't want and instead want it to be printed 3 times.
This is presentation I required:
Currently I have:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a53b72b8-0dda-468b-bffd-3e28d792a2d6">
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<queryString>
<![CDATA[select * from test]]>
</queryString>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.lang.String"/>
<field name="col4" class="java.lang.Integer"/>
<field name="col5" class="java.lang.Integer"/>
<summary>
<band height="214" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="214" uuid="a8663f8c-217c-4ef3-ab2c-a11120aea80e"/>
<rowGroup name="col11" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="6e0cb2ba-ea94-4b5e-a774-3092f6b0bd06"/>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="4787314d-3cb1-4f29-99d4-1443453e5d1b"/>
<text><![CDATA[Total col11]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="col21" width="60">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{col2}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="bf3d5e77-12a9-44cc-94d1-3f2a317f32d1"/>
<textFieldExpression><![CDATA[$V{col21}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="c21bf242-edbb-4533-9d7d-7120282703a5"/>
<text><![CDATA[Total col21]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col31" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col3}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="120" height="20" uuid="320dded3-882b-4e8d-a821-ce94996a72d2">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col31}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="e78a53ad-4437-41d1-8cea-ab1a2fdf09d3"/>
<text><![CDATA[Total col31]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col4_MEASURE1" class="java.lang.Integer" calculation="Count">
<measureExpression><![CDATA[$F{col4}]]></measureExpression>
</measure>
<measure name="col5_MEASURE1" class="java.lang.Integer" calculation="Count">
<measureExpression><![CDATA[$F{col5}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="ddc2801e-7492-4848-b7f7-422d7267cadb"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20" uuid="38136ac4-94aa-46ef-91ca-b32ac1d19aba">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="col31">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="0b620468-123a-434e-8a87-be8125b86470"/>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="d3c3da1b-7c66-48e5-8328-9c775e036229"/>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="08db97ef-0f91-4301-a552-2eec171c2b91"/>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="2fa36822-c633-4954-b6ad-bb2633dd827b"/>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col31">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a1545b3f-ac13-4e97-8720-3b526af18207"/>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="02c1d1d7-8b20-461e-8bd9-b2e4ceff02ed"/>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col21">
<cellContents mode="Opaque" style="Crosstab_CG">
<textField>
<reportElement x="0" y="0" width="60" height="10" uuid="94b61c57-3b18-4134-a48f-36394cf8ac28"/>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" uuid="b8b84ab6-a800-427e-8738-40dc17f8b7ae"/>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col21" columnTotalGroup="col31">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="e34172fb-29af-43aa-af6b-50bb63949236"/>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="232ba479-f365-4fb8-8402-4a9d50f79c6c"/>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>

The col1 and col2 in your sample are Rows Groups. This name (Row Group) tell us that JasperReports engine unions all non unique values in groups in case using Crosstab component. That is why values should be always ordered for grouping data right (as shown at image below).
The data in Row Groups will be grouped by JR engine and one group is drawing as one cell.
Does this mean that the problem has no solution? - No. Let's solve it!
Looks like you want "to join" col1 and col2 columns values. This means that the value of col1 Row Group can be added to the "column" of col2 Row Group.
Example
Datasource
It is enough to test sample with simple csv datasource.
col1,col2,col3,col4,col5
abcd,1,b,1c,434
abcd,2,c,2c,333
abcd,3,c,4c,333
abcd,3,c,4c,333
abcd,5,c,4c,333
abcd,3,e,3g,909
The name of data adapter for this datasource in the example below is values.csv. The first line from the file is skipped - it is contains the column's name.
Report template
We should set the width of first column (col1 Row Group) as zero and increase the width of second column (col2 Row Group) to place additionally value of col1. In this case the JR engine draws both both values for each unique col2 value. We still need the first column because we need value of col1 (the bucket for col1 Row Group).
The design in Jaspersoft Studio (JSS) looks like:
The jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Crosstab. Merged values" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="values.csv"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.lang.String"/>
<field name="col4" class="java.lang.Integer"/>
<field name="col5" class="java.lang.Integer"/>
<summary>
<band height="214" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="214"/>
<crosstabHeaderCell>
<cellContents style="Crosstab_CH">
<staticText>
<reportElement x="0" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<text><![CDATA[Col1]]></text>
</staticText>
<staticText>
<reportElement x="60" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<text><![CDATA[Col2]]></text>
</staticText>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="col11" width="0">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH"/>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="col21" width="120">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{col2}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression><![CDATA[$V{col21}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col31" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col3}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="120" height="20"/>
<textFieldExpression><![CDATA[$V{col31}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col4_MEASURE1" class="java.lang.Integer" calculation="Count">
<measureExpression><![CDATA[$F{col4}]]></measureExpression>
</measure>
<measure name="col5_MEASURE1" class="java.lang.Integer" calculation="Count">
<measureExpression><![CDATA[$F{col5}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA[$V{col4_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textFieldExpression><![CDATA[$V{col5_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
Output result
The result in JSS:

Related

How to format data in cells of crosstab using measures of different types

With regard to using crosstabs, is there a way to add any kind of formatting to the measures?
I have the data as follows.
I need to display col2, col4 as per the formatting specified for any geographical location. For example, in India, we show the date as 11/11/1986 and number as 1,00,000. Another country may show the data as 11.11.1986 and number as 1.00.000
How do I achieve this?
Also, while creating the crosstab, I do not add any calculated function to the crosstab, yet, it takes up the highest values for that combination of row group and column group. Why is this? Here is the picture of the same
And the jrxml for the same is as below
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="crosstabmeasure" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47b3f7d-1e00-4702-a900-be50a229f085">
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.sql.Timestamp"/>
<field name="col4" class="java.lang.String"/>
<summary>
<band height="211" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43"/>
<rowGroup name="col11" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="86c09a7f-46b5-4d2f-ba87-715f99d832a8"/>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="94fca0ea-1572-4d42-85d9-b06f92c73b6e"/>
<text><![CDATA[Total col11]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col41" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col4}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="120" height="20" uuid="137ef406-6a2e-4629-9d38-4858c4a5ae2c">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col41}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="5c71211d-f1db-4911-8923-2bdb208ddb99"/>
<text><![CDATA[Total col41]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col2_MEASURE1" class="java.lang.Integer">
<measureExpression><![CDATA[$F{col2}]]></measureExpression>
</measure>
<measure name="col3_MEASURE1" class="java.sql.Timestamp">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="861d0d3a-d774-4b0c-ae7d-ace315bf305c"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20" uuid="163ed502-e753-444a-942d-832d84da0a5f">
</reportElement>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="2576b9e2-3bba-40e3-aa15-5f4f0aada549"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="a111181f-b60f-4afd-8292-9e260c1b9ce2"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="9adf6c9c-acee-4673-8b70-a376e7d1cbb4"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="9baedeed-4770-4153-b639-afc0965e9467"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a2805e0a-080d-42be-ad86-a7e8e666f571"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="c485f69d-91e1-4b19-a8ab-bdbfa3cafcc6"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
It is better to stay measureExpression AS IS and apply formatting for textFieldExpression.
The textFieldExpression in crosstab can operate with crosstab's parameters values.
If the main Main dataset is using at crosstab we can use the
crosstab's parameters in cells of crosstab.
If the another dataset
is using at crosstab we can this dataset's parameters in cells of
crosstab.
Example
Datasource
The csv datasource is using in example.
col1,col2,col3,col4
a,a123,10,12/02/2016
a,a123,20,30/01/2016
a,a123,44,21/01/2016
a,b456,5,28/03/2016
b,a123,15,23/03/2015
b,b456,100,13/05/2015
b,b456,200,10/09/2015
b,b456,130,09/09/2017
The name of data adapter for this datasource in the example below is values.csv. The first line from the file is skipped - it is contains the column's name.
Report template
Col1 is using in rowGroups, col2 is using at columnGroups.
With help of measureExpression the crosstab showing the Sum of col3 for each group and the Highest date (col4).
The formatting will be applied for textFields. The parameter will be used for Date formatting.
In this example the Main dataset is using for showing data at crosstab. We need to pass the value of report's parameter to the crosstab's parameters, because we can't use report's parameters in crosstab (with rare exceptions).
<crosstabParameter name="dateFormat" class="java.text.SimpleDateFormat">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("SIMPLE_DATE_FORMAT")]]></parameterValueExpression>
</crosstabParameter>
- this is initialization of crosstab's parameter (dateFormat) with help of REPORT_PARAMETERS_MAP report's parameter. The value of REPORT_PARAMETERS_MAP parameter can be accessed from crosstab.
The value of report's parameter SIMPLE_DATE_FORMAT can be passed to the report for example with help of Java code.
The jrxml code:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Formatted measures" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="values.csv"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<parameter name="SIMPLE_DATE_FORMAT" class="java.text.SimpleDateFormat" isForPrompting="false">
<defaultValueExpression><![CDATA[new java.text.SimpleDateFormat("dd.MM.yyyy")]]></defaultValueExpression>
</parameter>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.String"/>
<field name="col3" class="java.lang.Integer"/>
<field name="col4" class="java.util.Date"/>
<summary>
<band height="270">
<crosstab>
<reportElement x="20" y="70" width="525" height="200" >
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<crosstabParameter name="dateFormat" class="java.text.SimpleDateFormat">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("SIMPLE_DATE_FORMAT")]]></parameterValueExpression>
</crosstabParameter>
<rowGroup name="col1" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<textFieldExpression><![CDATA[$V{col1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
</rowGroup>
<columnGroup name="col2" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col2}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col2}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
</columnGroup>
<measure name="col3_MEASURE" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<measure name="col4_MEASURE" class="java.util.Date" calculation="Highest">
<measureExpression><![CDATA[$F{col4}]]></measureExpression>
</measure>
<crosstabCell width="180" height="40">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField pattern="#,##0.00">
<reportElement x="0" y="0" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="180" height="20"/>
<textFieldExpression><![CDATA[$V{col2}.equals("a123") ? $P{dateFormat}.format($V{col4_MEASURE}) :
new SimpleDateFormat("dd/MM/yy").format($V{col4_MEASURE})]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
The expression for showing data can be complex as in this example. With help of expression:
<textFieldExpression><![CDATA[$V{col2}.equals("a123") ? $P{dateFormat}.format($V{col4_MEASURE}) :
new SimpleDateFormat("dd/MM/yy").format($V{col4_MEASURE})]]></textFieldExpression>
we are showing dates in different formats for different columns (col2).
Output result
The result in Jaspersoft Studio will be:
The sum of Integer values formatted with help of pattern attribute and the max value of Date values formatted with help of Java expression.

Crosstab applying calculated functions by default

I have a crosstab made out of the dataset as follows
I expect no calculation function on the measure columns. But, the report when it runs always takes the highest by default and the result looks as below. How do I get the report to just give the pivoted data and not perform any calculation on the measures?
I expect the data to look as shown in the picture below
Please find below the related jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="crosstabmeasure" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47b3f7d-1e00-4702-a900-be50a229f085">
<import value="org.apache.commons.lang3.time.*"/>
<import value="java.util.Date"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="set1" uuid="0271cb46-f184-47b2-8ab3-e6ee96ea33ef">
<parameter name="Locale" class="java.lang.String"/>
<parameter name="UtcOffSet" class="java.lang.Integer"/>
<queryString>
<![CDATA[select #curRank := #curRank + 1 AS rank, inter.*
from internatioinlization inter, (SELECT #curRank := 0) r
where 1 = case when 1 = 1 and $P{Locale} is not null and $P{UtcOffSet} is not null then 1 else 0 end]]>
</queryString>
<field name="rank" class="java.lang.Double"/>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.sql.Timestamp"/>
<field name="col4" class="java.lang.String"/>
</subDataset>
<parameter name="Locale" class="java.lang.String"/>
<parameter name="UtcOffSet" class="java.lang.Integer"/>
<queryString>
<![CDATA[select #curRank := #curRank + 1 AS rank, inter.*
from internatioinlization inter, (SELECT #curRank := 0) r
where 1 = case when 1 = 1 and $P{Locale} is not null and $P{UtcOffSet} is not null then 1 else 0 end]]>
</queryString>
<field name="rank" class="java.lang.Double"/>
<field name="col1" class="java.lang.String"/>
<field name="col2" class="java.lang.Integer"/>
<field name="col3" class="java.sql.Timestamp"/>
<field name="col4" class="java.lang.String"/>
<summary>
<band height="211" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43">
</reportElement>
<crosstabParameter name="Locale">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("Locale")]]></parameterValueExpression>
</crosstabParameter>
<crosstabParameter name="UtcOffSet" class="java.lang.Integer">
<parameterValueExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.get("UtcOffSet")]]></parameterValueExpression>
</crosstabParameter>
<crosstabDataset>
<dataset>
<datasetRun subDataset="set1" uuid="d255c9b9-fbb2-420a-8ef5-3236098654f1">
<datasetParameter name="Locale">
<datasetParameterExpression><![CDATA[$P{Locale}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="UtcOffSet">
<datasetParameterExpression><![CDATA[$P{UtcOffSet}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<rowGroup name="col11" width="60">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col1}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="86c09a7f-46b5-4d2f-ba87-715f99d832a8"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{col11}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="94fca0ea-1572-4d42-85d9-b06f92c73b6e"/>
<text><![CDATA[Total col11]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="col41" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{col4}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="120" height="20" uuid="137ef406-6a2e-4629-9d38-4858c4a5ae2c"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{col41}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="5c71211d-f1db-4911-8923-2bdb208ddb99"/>
<text><![CDATA[Total col41]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="col2_MEASURE1" class="java.lang.Integer">
<measureExpression><![CDATA[$F{col2}]]></measureExpression>
</measure>
<measure name="col3_MEASURE1" class="java.sql.Timestamp">
<measureExpression><![CDATA[$F{col3}]]></measureExpression>
</measure>
<crosstabCell width="120" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="861d0d3a-d774-4b0c-ae7d-ace315bf305c"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="60" y="0" width="60" height="20" uuid="163ed502-e753-444a-942d-832d84da0a5f"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1} != null ? DateFormat.getDateInstance(DateFormat.SHORT, new Locale($P{Locale}.split("-")[0], $P{Locale}.split("-")[1])).format(DateUtils.addMinutes($V{col3_MEASURE1},$P{UtcOffSet})) : null]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="2576b9e2-3bba-40e3-aa15-5f4f0aada549"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="a111181f-b60f-4afd-8292-9e260c1b9ce2"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="9adf6c9c-acee-4673-8b70-a376e7d1cbb4"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="9baedeed-4770-4153-b639-afc0965e9467"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col41">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a2805e0a-080d-42be-ad86-a7e8e666f571"/>
<textFieldExpression><![CDATA[$V{col2_MEASURE1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="c485f69d-91e1-4b19-a8ab-bdbfa3cafcc6"/>
<textFieldExpression><![CDATA[$V{col3_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
If you want to prevent bucketing/aggregation for the col1 row group, you can add a second row group (with no header cells) that has distinct values for each record. For instance:
<rowGroup name="RecNo" width="0">
<bucket class="java.lang.Integer">
<bucketExpression>$V{REPORT_COUNT}</bucketExpression>
</bucket>
</rowGroup>

jasper report cross tab condition in measures

I am working in JasperSoft studio 6.2
Here is a simple report with one cross tab (a mock up from the real issue). I want to add a condition in the measure, so that when the currency is gbp, the val should be multiplied by 3. But this seems not happening, the measure just shows the val regardless the currency.
This is what the report is showing now:
The cell at c1 and r2 should be 3, so is the cell at the c2 and r2
The expression for the measure
$F{currency} == "gbp"? $F{val}*3 : $F{val}
The dataset query
select 'c1' as cg, 'r1' as rg, 1 as val, 'aud' as currency
union all select 'c1' as cg, 'r2' as rg, 1 as val, 'gbp' as currency
union all select 'c2' as cg, 'r1' as rg, 1 as val, 'aud' as currency
union all select 'c2' as cg, 'r2' as rg, 1 as val, 'gbp' as currency
The report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-05-10T10:19:28 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test6" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="472d0a21-f9e0-4b4c-8830-53ce76baca95">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<queryString>
<![CDATA[select 'c1' as cg, 'r1' as rg, 1 as val, 'aud' as currency
union all select 'c1' as cg, 'r2' as rg, 1 as val, 'gbp' as currency
union all select 'c2' as cg, 'r1' as rg, 1 as val, 'aud' as currency
union all select 'c2' as cg, 'r2' as rg, 1 as val, 'gbp' as currency]]>
</queryString>
<field name="cg" class="java.lang.String"/>
<field name="rg" class="java.lang.String"/>
<field name="val" class="java.lang.Integer"/>
<field name="currency" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="220" splitType="Stretch">
<crosstab>
<reportElement x="0" y="20" width="555" height="200" uuid="db69b441-d09f-49f7-b290-7eec7275eb1b">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<rowGroup name="rg1" width="60" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{rg}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="6f2b3dc8-ae54-4dd9-b74d-8f708dfe0e52"/>
<textFieldExpression><![CDATA[$V{rg1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="23c06ac5-0336-4dec-a4f1-6a9e48d9b470"/>
<text><![CDATA[Total rg1]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="cg1" height="20" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{cg}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="9872abc3-cac8-4b20-8dac-8f3d294d6c0d"/>
<textFieldExpression><![CDATA[$V{cg1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="fc087f0f-321d-46eb-b4ac-44eea96ff044"/>
<text><![CDATA[Total cg1]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="val_MEASURE1" class="java.lang.Integer" calculation="Sum">
<measureExpression><![CDATA[$F{currency} == "gbp"? $F{val}*3 : $F{val}]]></measureExpression>
</measure>
<crosstabCell width="60" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="827bc665-96dc-4adc-9a75-e4549d146d79"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="cg1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="4d85b6d3-b844-4072-aa29-d33559efd678"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="rg1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="f83e2d2f-ad1f-47e7-ac36-567f47862219"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="rg1" columnTotalGroup="cg1">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="668927e0-801e-415d-ab82-36040ad4f830"/>
<textFieldExpression><![CDATA[$V{val_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
$F{currency}.equals("gbp") ? $F{val}*3 : $F{val}
You can search the difference between == and .equals.

Repeating row for every report

I have created a table report.
I have put no, agency name, year 1, year 2, year 3, year 4, year 5 and the total for the first row and the second row. I've put all sum of year 1, year 2, year 3, year 4, year 5 and total of agencies in the Detail band. After that, I put the line chart layout. In the end, I put the page break with $V{REPORT_COUNT} % 5==0 condition. But the problem is repetitive data along both the row. How to solve this problem? I want to view 5 row per page for an one report. The result are still the same.
Here i attach my code:
Update:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="charttest" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="99"/>
<parameter name="P_YEAR" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Documents and Settings\\NT\\Desktop\\CHART\\"]]></defaultValueExpression>
</parameter>
<field name="PARENT_NAME" class="java.lang.String"/>
<field name="PARENT_NAME_SECTOR" class="java.lang.String"/>
<field name="AGENCY_PARENT_CODE" class="java.lang.String"/>
<field name="AGENCY_CODE" class="java.lang.String"/>
<field name="AGENCY_NAME" class="java.lang.String"/>
<field name="YEAR" class="java.math.BigDecimal"/>
<field name="SECTOR_ID" class="java.lang.String"/>
<field name="SECTOR_NAME" class="java.lang.String"/>
<field name="DYEAR1" class="java.math.BigDecimal"/>
<field name="DYEAR2" class="java.math.BigDecimal"/>
<field name="DYEAR3" class="java.math.BigDecimal"/>
<field name="DYEAR4" class="java.math.BigDecimal"/>
<field name="DYEAR5" class="java.lang.String"/>
<field name="YR1" class="java.math.BigDecimal"/>
<field name="YR2" class="java.math.BigDecimal"/>
<field name="YR3" class="java.math.BigDecimal"/>
<field name="YR4" class="java.math.BigDecimal"/>
<field name="YR5" class="java.math.BigDecimal"/>
<variable name="YR1_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR1}]]></variableExpression>
</variable>
<variable name="YR2_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR2}]]></variableExpression>
</variable>
<variable name="YR3_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR3}]]></variableExpression>
</variable>
<variable name="YR4_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR4}]]></variableExpression>
</variable>
<variable name="YR5_1" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR5}]]></variableExpression>
</variable>
<variable name="YR1_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR1}]]></variableExpression>
</variable>
<variable name="YR2_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR2}]]></variableExpression>
</variable>
<variable name="YR3_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR3}]]></variableExpression>
</variable>
<variable name="YR4_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR4}]]></variableExpression>
</variable>
<variable name="YR5_2" class="java.math.BigDecimal" resetType="Column" calculation="Sum">
<variableExpression><![CDATA[$F{YR5}]]></variableExpression>
</variable>
<variable name="sumA" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{YR1}+$F{YR2}+$F{YR3}+$F{YR4}+$F{YR5}]]></variableExpression>
</variable>
<group name="Agency">
<groupExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></groupExpression>
<groupHeader>
<band height="192">
<textField>
<reportElement x="622" y="83" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{SECTOR_NAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="64" y="145" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{AGENCY_NAME}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="74" y="83" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DYEAR1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="18" y="83" width="56" height="20"/>
<textElement/>
<text><![CDATA[Year From :]]></text>
</staticText>
<staticText>
<reportElement x="18" y="104" width="56" height="20"/>
<textElement/>
<text><![CDATA[Year To :]]></text>
</staticText>
<staticText>
<reportElement x="574" y="83" width="48" height="20"/>
<textElement/>
<text><![CDATA[Sector :]]></text>
</staticText>
<staticText>
<reportElement x="18" y="145" width="46" height="20"/>
<textElement/>
<text><![CDATA[Agency :]]></text>
</staticText>
<textField>
<reportElement x="74" y="104" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DYEAR5}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="21" width="802" height="26"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[5 YEAR STATISTICS ON APPLICATION RECEIVED (BY ALL AGENCIES)]]></text>
</staticText>
<staticText>
<reportElement x="18" y="165" width="33" height="27"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No.]]></text>
</staticText>
<textField>
<reportElement x="425" y="178" width="85" height="14"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{DYEAR3}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="510" y="178" width="85" height="14"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{DYEAR4}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="595" y="178" width="85" height="14"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{DYEAR5}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="340" y="178" width="85" height="14"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{DYEAR2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="255" y="178" width="85" height="14"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{DYEAR1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="255" y="165" width="425" height="13"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Year]]></text>
</staticText>
<staticText>
<reportElement x="51" y="165" width="204" height="27"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Agency Name]]></text>
</staticText>
<staticText>
<reportElement x="680" y="165" width="85" height="27"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Total]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="395">
<lineChart>
<chart>
<reportElement x="30" y="42" width="772" height="353"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<dataset resetType="Group" resetGroup="Agency" incrementType="Report"/>
<categorySeries>
<seriesExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></seriesExpression>
<categoryExpression><![CDATA[$F{YEAR}]]></categoryExpression>
<valueExpression><![CDATA[$F{YR5}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot/>
</linePlot>
</lineChart>
<textField>
<reportElement x="340" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{YR2_2}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="18" y="0" width="237" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[ Total]]></text>
</staticText>
<textField>
<reportElement x="255" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{YR1_2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="425" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{YR3_2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="510" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{YR4_2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="595" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{YR5_2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="680" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[new Integer($V{YR1_1}.intValue() + $V{YR2_1}.intValue()+
$V{YR3_1}.intValue()+ $V{YR4_1}.intValue())+ $V{YR5_1}.intValue()]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="510" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{YR4}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="51" y="0" width="204" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{PARENT_NAME_SECTOR}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="18" y="0" width="33" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{COLUMN_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="255" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{YR1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="340" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{YR2}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="425" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{YR3}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="595" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{YR5}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="680" y="0" width="85" height="20"/>
<box>
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[new Integer($F{YR1}.intValue() + $F{YR2}.intValue()+ $F{YR3}.intValue()+ $F{YR4}.intValue())+ $F{YR5}.intValue()]]></textFieldExpression>
</textField>
<break>
<reportElement x="0" y="19" width="802" height="1">
<printWhenExpression><![CDATA[($V{REPORT_COUNT} % 5 == 0)]]></printWhenExpression>
</reportElement>
</break>
</band>
</detail>
</jasperReport>
If I understand you correctly, you want to have 5 detail rows followed by the graph, and then a linebreak? The reason this is not happening is because you have the linegraph printing after every detail row. So it never actually hits the 5th row. You need to move the line graph to the agnesi Group Footer 1 section.
UPDATE: If you only want the column header on the first page, then you need to add a printWhenExpression to it that has $V{PAGE_NUMBER}==1
2nd UPDATE: You have a few things wrong with your report.
One you put a page break in your Page Footer. That should not be
there. It makes does not make since to put a page break in the footer
at all.
Two You have multiple detail sections. I do not think that is going
to work the way you expect it to. The items in your Detail 2 section
more than likely be in the Agency Group Footer 1 with NO Page
Break.
Three your column header does not seem right. You are referencing
Fields in there. Fields is the data in your datasource that are
iterated over in the group and detail section. As a best Guess this
should be moved into the Agency Group Header 1 instead of the
column header.
Lastly the only place you should put a page break in your case is in
the Detail 1 section with the print when expression
($V{REPORT_COUNT} % 5) == 0
Something I find that helps me keep things clearer is to delete the sections altogether that I am not using. Once you do the things above I told you about, you could for example delete the title, page header, column header, page footer, and summary sections.

How to filter data in table (crosstab) by date

I need some help in creating report using iReport for this layout. I am able to create records using crosstab, but its creating duplicate records.
Male Female
Date
Total Count
Query
SELECT table1.`gender` AS table1_gender,
registration_details.`date_reg` AS registration_details_date_reg
FROM
`table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`
where
gender is present in table1 (candidate_id : pk)
date_reg is present in registration_details
The jrxml:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report12" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<style name="Crosstab Data Text" hAlign="Center"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="New Dataset 1">
<queryString language="SQL">
<![CDATA[SELECT
table1.`gender` AS table1_gender,
registration_details.`date_reg` AS registration_details_date_reg
FROM
`table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`]]>
</queryString>
<field name="table1_gender" class="java.lang.String"/>
<field name="registration_details_date_reg" class="java.sql.Date"/>
</subDataset>
<subDataset name="Table Dataset 1"/>
<queryString language="SQL">
<![CDATA[SELECT
table1.`gender` AS table1_gender,
registration_details.`date_reg` AS registration_details_date_reg
FROM
`table1` table1 INNER JOIN `date_reg` date_reg ON table1.`candidate_id` = registration_details.`candidate_id`]]>
</queryString>
<field name="table1_gender" class="java.lang.String"/>
<field name="date_reg" class="java.sql.Date"/>
<detail>
<band height="125" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="125"/>
<crosstabDataset>
<dataset>
<datasetRun subDataset="New Dataset 1">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<rowGroup name="date_reg" width="70" totalPosition="End">
<bucket>
<bucketExpression class="java.lang.String"><![CDATA[(new SimpleDateFormat("yyyy-MM-dd")).format($F{date_reg})]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="70" height="25"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$V{date_reg}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="70" height="25"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Total date_reg]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="table1_gender" height="30" totalPosition="End">
<bucket>
<bucketExpression class="java.lang.String"><![CDATA[$F{table1_gender}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$V{student_gender}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="50" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Total student_gender]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="table1_genderMeasure" class="java.lang.Integer" calculation="Count">
<measureExpression><![CDATA[$F{table1_gender}]]></measureExpression>
</measure>
<crosstabCell width="50" height="25">
<cellContents>
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="25" rowTotalGroup="date_reg">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="50" columnTotalGroup="student_gender">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell rowTotalGroup="date_reg" columnTotalGroup="table1_gender">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{table1_genderMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</detail>
</jasperReport>
Currently its showing all the records , Need suggestions/help in creating report
Where a User will be able to fetch records by providing date.
also its printing single records multiple time.
I would appreciate any help.
For filtering data by date you can add paramater (java.lang.String or java.util.Date) type and use it in the query.
The example:
<parameter name="dateParam" isForPrompting="false" class="java.lang.String"/>
...
<parameter name="dqlDateFilter" isForPrompting="false" class="java.lang.String">
<defaultValueExpression ><![CDATA[$P{dateParam} == null ? "1=1" : "registration_details.date_reg=$P{dateParam}"]]></defaultValueExpression>
</parameter>
...
<queryString language="SQL">SELECT.... FROM.... WHERE $P!{dqlDateFilter}</queryString>
You should write the correct date filter for your case.