Jasper reports - Changing date and number pattern as per user locale - jasper-reports

I have a crosstab where in I need to display dates and numbers as per the country's locale. I understand I need to use the text expression, but I am unable to figure how must I use with parameters. The locale comes in the form of 'en-IN'(for India), 'de-DE'(for Germany) and so on for all the countries. The date and number formats must change as per the locale of the person who as logged in
I have been able to obtain the user locale in the parameter. But, I do not know how to use it in the crosstab.
PFB the jrxml. I keep getting the error expression ID not found
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2016-11-04T12:23:19 -->
<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">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/>
<import value="org.apache.commons.lang3.time.*"/>
<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">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<parameter name="UtcOffSet" class="java.lang.Integer">
<defaultValueExpression><![CDATA[330]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col2" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col3" class="java.sql.Timestamp">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col4" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
</subDataset>
<parameter name="Locale" class="java.lang.String">
<defaultValueExpression><![CDATA["en-IN"]]></defaultValueExpression>
</parameter>
<parameter name="UtcOffSet" class="java.lang.Integer">
<defaultValueExpression><![CDATA["fi-FI"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select * from internatioinlization]]>
</queryString>
<field name="col1" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col2" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col3" class="java.sql.Timestamp">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="col4" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<summary>
<band height="211" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43"/>
<crosstabParameter name="Parameter1"/>
<crosstabParameter name="Parameter2" class="java.lang.Integer"/>
<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"/>
<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.util.Date">
<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">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$V{col3_MEASURE1} != null ? DateFormat.getDateInstance(DateFormat.SHORT, new Locale($P{Parameter1}.split("-")[0], $P{Parameter1}.split("-")[1])).format(DateUtils.addMinutes($V{col3_MEASURE1},$P{Parameter2})) : 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>
Thanks in advance
Rathi

Mh, that's actually a weird problem, because usually the date and number formats are done by the Java engine.
You could create a resource bundle and add pattern.date = DD.MM.YYYY to it.
In the date textfield just change the pattern expression to $R{pattern.date} and you are ready to go.

Related

How to change back color of a column when value changes in it with respect to previous column value.(Conditional styling)

I have a Column measure in Cross tab which needs to be styled diffrently when column value changes.For Instance my current output looks like this
I am trying to color the column in this manner
Output format here is xls.
SHIPCITY is a parent column header under which there are SHIPADRESS below that header.
Below is the jrxml that produces the current output.you can reproduce the issue using it.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0 -->
<!-- 2017-09-04T18:07:58 -->
<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="ConditionalStyling" pageWidth="1400" pageHeight="842" columnWidth="1400" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="c83c5a57-1109-4513-a122-d0bfbf7fd308">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<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>
<style name="Style1" mode="Opaque" forecolor="#000000" backcolor="#F7211E"/>
<queryString>
<![CDATA[select * from orders order by customerid, shipcountry , shipcity , shipaddress ]]>
</queryString>
<field name="ORDERID" class="java.lang.Integer"/>
<field name="CUSTOMERID" class="java.lang.String"/>
<field name="EMPLOYEEID" class="java.lang.Integer"/>
<field name="ORDERDATE" class="java.sql.Timestamp"/>
<field name="REQUIREDDATE" class="java.sql.Timestamp"/>
<field name="SHIPPEDDATE" class="java.sql.Timestamp"/>
<field name="SHIPVIA" class="java.lang.Integer"/>
<field name="FREIGHT" class="java.math.BigDecimal"/>
<field name="SHIPNAME" class="java.lang.String"/>
<field name="SHIPADDRESS" class="java.lang.String"/>
<field name="SHIPCITY" class="java.lang.String"/>
<field name="SHIPREGION" class="java.lang.String"/>
<field name="SHIPPOSTALCODE" class="java.lang.String"/>
<field name="SHIPCOUNTRY" class="java.lang.String"/>
<summary>
<band height="300">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<crosstab>
<reportElement x="0" y="0" width="1400" height="300" uuid="34cf7e8d-c567-485d-85a7-798c27118f97">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
</reportElement>
<crosstabHeaderCell>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="90" height="40" uuid="de2c1860-2c17-451c-93c1-691b7a2d52c6"/>
<text><![CDATA[CUSTOMER_ID]]></text>
</staticText>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="CUSTOMERID" width="90">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{CUSTOMERID}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="5b8cdacd-7f44-4dcf-8db0-6b6c58c3fb32"/>
<textFieldExpression><![CDATA[$V{CUSTOMERID}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<staticText>
<reportElement x="0" y="0" width="0" height="0" uuid="08c3c9ff-49ec-435c-9fb9-10a97aeb16ff"/>
<text><![CDATA[Total CUSTOMERID]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="SHIPCITY" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SHIPCOUNTRY}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement style="Style1" x="0" y="0" width="100" height="20" uuid="f68a5ef8-d957-4568-b895-93907688b107"/>
<textFieldExpression><![CDATA[$V{SHIPCITY}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CG">
<staticText>
<reportElement x="0" y="0" width="0" height="0" uuid="9893aa3b-7eae-42de-b18d-30a92e1e6580"/>
<text><![CDATA[Total SHIPCITY]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<columnGroup name="SHIPADDRESS" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{SHIPADDRESS}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="969f7bc4-600e-4310-aa3f-526c278b6fde"/>
<textFieldExpression><![CDATA[$V{SHIPADDRESS}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CT">
<staticText>
<reportElement x="0" y="0" width="0" height="0" forecolor="#FFFFFF" uuid="08ba2a79-077d-4f94-bc55-62939d55e557"/>
<text><![CDATA[Total SHIPADDRESS]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="ORDERID_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{ORDERID}]]></measureExpression>
</measure>
<crosstabCell width="100" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="100" height="20" uuid="2ea2bac8-82f5-42b8-a6fe-2a397cadc9b2"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="SHIPADDRESS">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="46cc1294-ec97-4dcf-9189-f77fb9e87538"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" columnTotalGroup="SHIPCITY">
<cellContents mode="Opaque" style="Crosstab_CG">
<textField>
<reportElement x="0" y="0" width="60" height="20" uuid="4bade212-3c6d-4027-bb5f-9e22ee527401"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="58c77e0a-d003-4f5f-9f0e-8f6e0e5a12d5"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID" columnTotalGroup="SHIPADDRESS">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="163a57aa-ff00-4362-b078-8106fb513043"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="60" height="20" rowTotalGroup="CUSTOMERID" columnTotalGroup="SHIPCITY">
<cellContents mode="Opaque" style="Crosstab_CT">
<textField>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="de152f44-e188-42ef-9e22-7e8346e0f860"/>
<textFieldExpression><![CDATA[$V{ORDERID_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
I can create the two conditions but could not think of logic to apply in conditional expression. Any thoughts on how i can achieve such conditional styling?
This was but tricky.I added one more column in my SQL for coloring.Using dense_rank() function i gave rank to the results and grouped them on country name. So basically those rows which has same country name have same rank and then i ordered this based on country name.
On the jasper side. I added this coloring column in column group and set its width to zero and then added my conditional style logic to the odd and even values. This is the logic i was looking for.

How to introduce the page break after pre-defined number of rows in the jr:table component?

I am using jasper report version 6.1 and wanted page break after pre-defined number of rows in the jr:table component. I have also tried doing the same in version 5 and it works fine but in version 6+ I am not able to do it.
Sharing the links which I followed if any one have other solution please let me know.
http://community.jaspersoft.com/wiki/ireport-how-introduce-page-break-after-pre-defined-number-rows-table-component
http://community.jaspersoft.com/questions/845487/inserting-break-table-print-only-10-rows-page-jasper-reports-372
This is what I have tried:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 -->
<!-- 2017-05-29T15:29:33 -->
<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_4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="957c1fea-8994-4195-9d7a-2bbf0baf7180">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Max apex"/>
<style name="Table_TH" 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="Table_CH" 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="Table_TD" 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="Dataset1" uuid="435d51b0-6d3e-442e-9a96-ae7412b12278">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Max apex"/>
<queryString>
<![CDATA[select * from dept]]>
</queryString>
<field name="DEPTNO" class="java.math.BigDecimal"/>
<field name="DNAME" class="java.lang.String"/>
<field name="LOC" class="java.lang.String"/>
<group name="DEPTNO">
<groupExpression><![CDATA[$F{DEPTNO}]]></groupExpression>
</group>
<group name="DNAME">
<groupExpression><![CDATA[$F{DNAME}]]></groupExpression>
</group>
<group name="LOC">
<groupExpression><![CDATA[$F{LOC}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[select * from dept]]>
</queryString>
<field name="DEPTNO" class="java.math.BigDecimal"/>
<field name="DNAME" class="java.lang.String"/>
<field name="LOC" class="java.lang.String"/>
<group name="DEPTNO">
<groupExpression><![CDATA[$F{DEPTNO}]]></groupExpression>
</group>
<group name="DNAME">
<groupExpression><![CDATA[$F{DNAME}]]></groupExpression>
</group>
<group name="LOC">
<groupExpression><![CDATA[$F{LOC}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="145" splitType="Stretch">
<componentElement>
<reportElement positionType="FixRelativeToBottom" x="10" y="0" width="500" height="110" uuid="b37c89ae-600a-4fb8-ac64-e142bfe22e13"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="8f84378b-9508-4763-8265-69e68c41febe">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="100" uuid="00a00921-f5fa-4352-924c-f0531c919f71">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="d88580f8-05d2-4eb0-a098-00e877c58c39"/>
<text><![CDATA[DEPTNO]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="15fda94a-b686-4808-b55c-3e08a8e86187"/>
<textFieldExpression><![CDATA[$F{DEPTNO}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="140" uuid="72e58aec-00f1-4937-8600-b32a6010d4d6">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="130" height="30" uuid="942c89ca-e914-4809-bb18-3b7065b413f7"/>
<text><![CDATA[DNAME]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="130" height="30" uuid="8b936e63-5f84-4fd7-b21c-8c08fb9550a5"/>
<textFieldExpression><![CDATA[$F{DNAME}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="140" uuid="f312cbac-4554-492c-928f-dd84b5a55d42">
<jr:columnHeader style="Table_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="120" height="30" uuid="ce385917-88aa-4e51-9cae-a7a142f78323"/>
<text><![CDATA[LOC]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="120" height="30" uuid="0e43f425-558c-4001-9c44-ca14798bcb75"/>
<textFieldExpression><![CDATA[$F{LOC}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The solution to use a a group expression inside the subdatset works perfectly fine also in jasper reports v6+.
Example (built from code and data from this answer)
Adding groupExpression to the subDataset to break to new page every 2 records ($V{REPORT_COUNT}-1)/2)
<subDataset name="tableDataset" uuid="7a53770f-0350-4a73-bfc1-48a5f6386594">
<field name="User" class="java.lang.String"/>
<field name="Rep" class="java.math.BigDecimal"/>
<group name="pageBreakGroup" isStartNewPage="true">
<groupExpression><![CDATA[(int)(($V{REPORT_COUNT}-1)/2)]]></groupExpression>
</group>
</subDataset>
Expand code snippet for full 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="reputation" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a88bd694-4f90-41fc-84d0-002b90b2d73e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="CVS"/>
<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>
<subDataset name="tableDataset" uuid="7a53770f-0350-4a73-bfc1-48a5f6386594">
<field name="User" class="java.lang.String"/>
<field name="Rep" class="java.math.BigDecimal"/>
<group name="pageBreakGroup" isStartNewPage="true">
<groupExpression><![CDATA[(int)(($V{REPORT_COUNT}-1)/2d)]]></groupExpression>
</group>
</subDataset>
<parameter name="displayRecordNumber" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="50">
<componentElement>
<reportElement key="table" style="table" x="0" y="0" width="555" height="47" uuid="76ab08c6-e757-4785-a43d-b65ad4ab1dd5"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="tableDataset" uuid="07e5f1c2-af7f-4373-b653-c127c47c9fa4">
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="918270fe-25c8-4a9b-a872-91299cddbc31">
<printWhenExpression><![CDATA[$P{displayRecordNumber}]]></printWhenExpression>
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30" uuid="5cd6da41-01d5-4f74-99c2-06784f891d1e"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Record number]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="5fe48359-0e7e-44b2-93ac-f55404189832"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7979d8a2-4e3c-42a7-9ff9-86f8e0b164bc">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30" uuid="61d5f1b6-7677-4511-a10c-1fb8a56a4b2a"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Username]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="a3cdb99d-3bf6-4c66-b50c-259b9aabfaef"/>
<box leftPadding="3" rightPadding="3"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{User}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="625e4e5e-5057-4eab-b4a9-c5b22844d25c">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="90" height="30" uuid="e1c07cb8-a44c-4a8d-8566-5c86d6671282"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Reputation]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<textField pattern="#,##0">
<reportElement x="0" y="0" width="90" height="30" uuid="6be2d79f-be82-4c7b-afd9-0039fb8b3189"/>
<box leftPadding="3" rightPadding="3"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{Rep}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</title>
</jasperReport>
Result in JasperStudio version 6.2
As you can see 3 pages (2 records on each, total record count 5).

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>

report preview flashes and disappears

When i'm trying to preview the data in IReports by clicking the preview tab, it is just flashing and going back, but i'm unable to see the data.
Below is my XML.
<?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="report5" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b8a981bc-ae9b-4fcf-8400-f9ecea0567f2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="Crosstab Data Text" hAlign="Center"/>
<queryString>
<![CDATA[SELECT
`Date assigned` AS Date_assigned,
Units,
`Assigned to PS` AS Assigned_to_PS
FROM
[Sheet1$]
]]>
</queryString>
<field name="Date_assigned" class="java.sql.Timestamp"/>
<field name="Units" class="java.lang.Double"/>
<field name="Assigned_to_PS" class="java.lang.String"/>
<group name="Date_assigned">
<groupExpression><![CDATA[$F{Date_assigned}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<crosstab>
<reportElement uuid="db476b5b-d93f-4819-a8f6-174bfc88c9b7" x="0" y="0" width="802" height="125"/>
<rowGroup name="Date_assigned" width="70" totalPosition="End">
<bucket class="java.util.Date">
<bucketExpression><![CDATA[$F{Date_assigned}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="cb26a0e2-7fa8-4124-be7f-f91e491801f7" style="Crosstab Data Text" x="0" y="0" width="70" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{Date_assigned}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement uuid="c97deff9-a499-4330-aa84-baf20315a1de" x="0" y="0" width="70" height="25"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Total Date_assigned]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="Assigned_to_PS" height="30" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Assigned_to_PS}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents backcolor="#F0F8FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="7e26e7de-b54f-4490-9ea1-b087247e9c06" style="Crosstab Data Text" x="0" y="0" width="50" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$V{Assigned_to_PS}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement uuid="86c2ceb5-b2d2-4cc7-953e-0c039e807ec1" x="86" y="0" width="50" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Total Assigned_to_PS]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="UnitssMeasure" class="java.lang.Double" calculation="Sum">
<measureExpression><![CDATA[$F{Unitss}]]></measureExpression>
</measure>
<crosstabCell width="120" height="38">
<cellContents>
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="7729498a-0309-4052-a002-e58592da972b" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{UnitssMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="120" height="61" rowTotalGroup="Date_assigned">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="35ba6c60-5505-4eba-be7b-8627a9516c7d" style="Crosstab Data Text" x="0" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{UnitssMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="136" height="38" columnTotalGroup="Assigned_to_PS">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="c260e58c-5377-4582-bdfe-59a3f337feee" style="Crosstab Data Text" x="86" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{UnitssMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell width="136" height="61" rowTotalGroup="Date_assigned" columnTotalGroup="Assigned_to_PS">
<cellContents backcolor="#BFE1FF" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement uuid="468233cd-75a6-4278-ba3f-de35032a5459" style="Crosstab Data Text" x="86" y="0" width="50" height="25"/>
<textElement/>
<textFieldExpression><![CDATA[$V{UnitssMeasure}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
This is actually a pivot table from excel data source, please let me know how do i preview it. And also i'm not getting any errors.
expected output is
Amreen Anirudh Anand Total
7/1/2013 158 158
7/2/2013 23 23
7/3/2013 152 748 900
7/4/2013
7/5/2013
7/6/2013 435 435
7/7/2013 170 170
7/8/2013 66 66
7/9/2013 33 33 66
Total 1037 748 33 1818
Thanks