Crosstab applying calculated functions by default - jasper-reports

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>

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 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.

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

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.

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.

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.