How to create a column footer for Jasper Report? - jasper-reports

I am creating an Excel using Jasper Report. I want to create a footer at the end of the columns which has a total. Eg:
Col 1 | Col 2
1.0 1.0
2.0 3.0
Total 3.0 4.0
I have in my XML:
...
<variable name="totalCol1" class="java.math.BigDecimal" calculation="Sum">
<variableExpression><![CDATA[$F{col1}]]></variableExpression>
</variable>
<variable name="totalCol2" class="java.math.BigDecimal" calculation="Sum">
<variableExpression><![CDATA[$F{col2}]]></variableExpression>
</variable>
...
<detail>
<band height="83" splitType="Prevent">
<crosstab isRepeatColumnHeaders="false" columnBreakOffset="0" ignoreWidth="true">
....
....
</crosstab>
</band>
</detail>
<columnFooter>
<band height="210" splitType="Prevent">
<textField>
<reportElement x="2210" y="180" width="100" height="30" uuid="d4580669-65c4-46c2-b7ca-9e10624d9651"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{lblTotal}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="2310" y="180" width="100" height="30" uuid="1e41e36a-6eca-43d6-8096-edc893686f92"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{totalcol1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="2410" y="180" width="100" height="30" uuid="ffff6945-f711-44cf-8356-092f3f3da688"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{totalCol2}]]></textFieldExpression>
</textField>
</band>
</columnFooter>
Columns 1 and 2 appears. But neither the label for Total nor the sum appears. Can someone help? If you need more info, please comment. Thanks in advance.

Related

Why is my expression off by 1 record?

I have a report that i am making using iReport and I have an equation that is helping me find duplicate Estimated Shipping variables and make the initial number stay the same but the ones displayed after it appear as 0. I want this because the report shows the changes made to the Sales Order but I dont want the report showing that the person was charged the initial Estimated Shipping ammount- every time.
The equation I am using to find the duplicates is
$V{SOID_Count}<=1?$F{SOITEM_UNITPRICE}:0
This works but if you notice in this picture the numbers are behind by one.
It is subtracting the Estimated Shipping amount that was above it- from the current Actual Shipping amount that you are on.
So how can I alter my counter equation to fix this?
Thank you for any help!
This 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="ShippingPriceDifference" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="97636279-f825-4b72-b9f8-8ce9740dce34">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="To" class="java.util.Date">
<parameterDescription><![CDATA[asdf]]></parameterDescription>
</parameter>
<parameter name="From" class="java.util.Date"/>
<queryString>
<![CDATA[SELECT
CUSTOMER."NAME" AS CUSTOMER_NAME,
SO."NUM" AS SO_NUM,
COMPANY."NAME" AS COMPANY_NAME,
SHIPCARTON."FREIGHTAMOUNT" AS SHIPCARTON_FREIGHTAMOUNT,
SHIP."SOID" AS SHIP_SOID,
SOITEM."UNITPRICE" AS SOITEM_UNITPRICE,
PRODUCT."PARTID" AS PRODUCT_PARTID,
SHIP."DATESHIPPED" AS SHIP_DATESHIPPED,
SOITEM."SOID" AS SOITEM_SOID
FROM
"CUSTOMER" CUSTOMER INNER JOIN "SO" SO ON CUSTOMER."ID" = SO."CUSTOMERID"
INNER JOIN "SHIP" SHIP ON SO."ID" = SHIP."SOID"
INNER JOIN "SOITEM" SOITEM ON SO."ID" = SOITEM."SOID"
INNER JOIN "PRODUCT" PRODUCT ON SOITEM."PRODUCTID" = PRODUCT."ID"
INNER JOIN "SHIPCARTON" SHIPCARTON ON SHIP."ID" = SHIPCARTON."SHIPID",
"COMPANY" COMPANY
WHERE
PRODUCT."PARTID" = 947
AND SHIP."DATESHIPPED" BETWEEN $P{From} AND $P{To}
AND SHIPCARTON."FREIGHTAMOUNT" != 0
ORDER BY
2 ASC]]>
</queryString>
<field name="CUSTOMER_NAME" class="java.lang.String"/>
<field name="SO_NUM" class="java.lang.String"/>
<field name="COMPANY_NAME" class="java.lang.String"/>
<field name="SHIPCARTON_FREIGHTAMOUNT" class="java.lang.Double"/>
<field name="SHIP_SOID" class="java.lang.Integer"/>
<field name="SOITEM_UNITPRICE" class="java.lang.Double"/>
<field name="PRODUCT_PARTID" class="java.lang.Integer"/>
<field name="SHIP_DATESHIPPED" class="java.sql.Timestamp"/>
<field name="SOITEM_SOID" class="java.lang.Integer"/>
<variable name="shipPriceDif" class="java.lang.Double">
<variableExpression><![CDATA[($F{SHIPCARTON_FREIGHTAMOUNT})- ($V{estimatedShipping})]]></variableExpression>
</variable>
<variable name="totalShipPriceDif" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{shipPriceDif}]]></variableExpression>
</variable>
<variable name="SOID_Count" class="java.lang.Integer" resetType="Group" resetGroup="SOID" calculation="Count">
<variableExpression><![CDATA[$F{SOITEM_SOID}]]></variableExpression>
</variable>
<variable name="estimatedShipping" class="java.lang.Double">
<variableExpression><![CDATA[$V{SOID_Count}<=1?$F{SOITEM_UNITPRICE}:0]]> </variableExpression>
</variable>
<group name="SOID">
<groupExpression><![CDATA[$F{SOITEM_SOID}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="27" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="25" uuid="64a1704a-b221-48a4-8186-1b855ead5acf"/>
<textElement textAlignment="Center">
<font fontName="SansSerif" size="16" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{COMPANY_NAME}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="59" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="555" height="25" uuid="e20cae54-5d75-4e81-800c-55390d1ec465"/>
<textElement textAlignment="Center">
<font fontName="SansSerif" size="14"/>
</textElement>
<text><![CDATA[Shipping Price Difference ]]></text>
</staticText>
<staticText>
<reportElement x="0" y="25" width="167" height="20" uuid="41be06d8-8fdf-4e3b-b526-1aea092ea734"/>
<textElement textAlignment="Right">
<font fontName="SansSerif" size="14" isBold="false"/>
</textElement>
<text><![CDATA[Date Range:]]></text>
</staticText>
<staticText>
<reportElement x="267" y="25" width="20" height="20" uuid="a402544b-73b3-4132-8161-be4c202e9b14"/>
<textElement textAlignment="Center">
<font fontName="SansSerif" size="14" isBold="false"/>
</textElement>
<text><![CDATA[-]]></text>
</staticText>
<textField>
<reportElement x="287" y="25" width="100" height="20" uuid="85e7fe2b-8149-4b18-8410-16b026cdb0f3"/>
<textElement verticalAlignment="Middle">
<font fontName="SansSerif" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{To}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="167" y="25" width="100" height="20" uuid="ea618bea-9201-4eba-abff-cfdc891ac76f"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="SansSerif" size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{From}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="21" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="140" height="20" uuid="82883a63-752d-4265-8158-a5129b617b7d"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Customer Name]]></text>
</staticText>
<staticText>
<reportElement x="140" y="0" width="75" height="20" uuid="2d302854-c68c-4e5a-b94b-900c88937b9d"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[SO #]]></text>
</staticText>
<staticText>
<reportElement x="455" y="0" width="100" height="20" uuid="50c6ba0f-a5df-4aa3-8a47-282271055053"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Difference]]></text>
</staticText>
<line>
<reportElement x="0" y="19" width="555" height="1" uuid="be790d1c-d6d6-4169-b743-a98654c025e9"/>
</line>
<staticText>
<reportElement x="215" y="0" width="120" height="20" uuid="ffbe1333-86b8-435f-b914-46bb1c747683"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Estimated Shipping]]></text>
</staticText>
<staticText>
<reportElement x="335" y="0" width="120" height="20" uuid="3f683f6b-19f6-49dd-9ee1-787b216aaa2f"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Actual Shipping]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="0" y="0" width="140" height="20" isRemoveLineWhenBlank="true" uuid="fdd69c30-9da5-4bd2-a7b8-44a506e2d7ff"/>
<textFieldExpression><![CDATA[$F{CUSTOMER_NAME}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" hyperlinkType="Reference">
<reportElement x="140" y="0" width="75" height="20" isRemoveLineWhenBlank="true" forecolor="#000099" uuid="19db6cb8-af37-46e6-9227-f1b55fc49f22"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{SO_NUM}]]></textFieldExpression>
<anchorNameExpression><![CDATA["SONum"]]></anchorNameExpression>
<hyperlinkReferenceExpression><![CDATA[$F{SO_NUM}]]></hyperlinkReferenceExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="335" y="0" width="120" height="20" isRemoveLineWhenBlank="true" uuid="006475e5-d36f-4482-97cf-2c2eda2d5a66"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{SHIPCARTON_FREIGHTAMOUNT}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="215" y="0" width="120" height="20" isRemoveLineWhenBlank="true" uuid="376d9c76-1d96-48ea-ac4a-40770ba28867"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{estimatedShipping}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00;-#,##0.00" isBlankWhenNull="true">
<reportElement x="455" y="0" width="100" height="20" isRemoveLineWhenBlank="true" uuid="c236c087-e6f4-4de6-a3d6-8abb8b798346"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{shipPriceDif}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="22" splitType="Stretch">
<textField>
<reportElement x="435" y="0" width="80" height="20" uuid="64e6c2aa-58eb-4994-83c3-16cb70197fef"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="515" y="0" width="40" height="20" uuid="09e2e08b-c9b1-4a5b-95fd-1c0a0dba17a2"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="22" splitType="Stretch">
<textField pattern="#,##0.00;-#,##0.00">
<reportElement x="150" y="1" width="75" height="20" uuid="8ab3526d-e89e-4043-86dd-52d89a2b7b21"/>
<textElement verticalAlignment="Top">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{totalShipPriceDif}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="140" y="1" width="10" height="20" uuid="110043fb-4dde-414e-b07f-f79cbb8839ab"/>
<textElement textAlignment="Right">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[$]]></text>
</staticText>
<line>
<reportElement x="0" y="0" width="555" height="1" uuid="e81602ee-7eab-43f3-90c1-cf69086623a9"/>
</line>
<staticText>
<reportElement x="0" y="1" width="140" height="20" uuid="095559e8-33e4-4a1a-9537-f8dff2b533d6"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Total Cost Difference :]]></text>
</staticText>
</band>
</summary>
</jasperReport>
Your problem is that the $V{estimatedShipping} is evaluated after your variable $V{shipPriceDif} since its after in your variable definition, or move it above or dump it...
Just calculate the Difference in the textField
<textField pattern="#,##0.00;-#,##0.00" isBlankWhenNull="true">
<reportElement x="455" y="0" width="100" height="20" isRemoveLineWhenBlank="true" uuid="c236c087-e6f4-4de6-a3d6-8abb8b798346"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$V{estimatedShipping}.doubleValue()-$F{SHIPCARTON_FREIGHTAMOUNT}.doubleValue()]]></textFieldExpression>
</textField>
The output of this would be:
+-------+-----------+--------+------------+
| SO# | Estimated | Actual | Difference |
+-------+-----------+--------+------------+
| 46137 | 700 | 58,38 | 641,62 |
| 46137 | 0 | 57,12 | -57.12 |
| 46137 | 0 | 28,29 | -28,29 |
| 46148 | 0,85 | 267,32 | -266,47 |
+-------+-----------+--------+------------+

How to make the row not repeating properly according the field

i have create one statistical report according the gender.
The field names Jantina.
I have a problem when remove the Print repeating values. I just want the field is not repeating according the Jantina field. But unfortunately the row not repeating all the row without following the Jantina.
How to do that? Anyone got the idea?
This is my 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="penyata_bulanan_ikut_negeri_jantina_test" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="bulan" class="java.lang.Integer">
<defaultValueExpression><![CDATA[new Integer(-1)]]></defaultValueExpression>
</parameter>
<parameter name="tahun" class="java.lang.Integer">
<defaultValueExpression><![CDATA[new Integer(-1)]]></defaultValueExpression>
</parameter>
<parameter name="negeri" class="java.lang.Integer">
<defaultValueExpression><![CDATA[new Integer(00)]]></defaultValueExpression>
</parameter>
<parameter name="jantina" class="java.lang.Long">
<defaultValueExpression><![CDATA[new Long(2)]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT #row := #row + 1 as r,bulan,tahun,negeri,jantina,
bilmale,jds,jumall,
ROUND(CAST((bilmale*100 /(jumall))AS DECIMAL(7,3)),2) as percent,
ROUND(CAST((jds*100 /(jumall))AS DECIMAL(7,3)),2) as p_jdk,
countstate
FROM some_table
group by date_format(X.createDate,'%Y' ),date_format(X.createDate,'%M' ),X.male,X.state
order by 1 asc) as a,(select #row := 0) as r]]>
</queryString>
<field name="r" class="java.lang.Long"/>
<field name="bulan" class="java.lang.String"/>
<field name="tahun" class="java.lang.String"/>
<field name="negeri" class="java.lang.String"/>
<field name="jantina" class="java.lang.String"/>
<field name="bilmale" class="java.math.BigDecimal"/>
<field name="jds" class="java.math.BigDecimal"/>
<field name="jumall" class="java.math.BigDecimal"/>
<field name="percent" class="java.math.BigDecimal"/>
<field name="p_jdk" class="java.math.BigDecimal"/>
<field name="countstate" class="java.lang.Long"/>
<sortField name="bulan"/>
<sortField name="tahun"/>
<sortField name="negeri"/>
<sortField name="jantina"/>
<group name="bulan">
<groupExpression><![CDATA[$F{bulan}]]></groupExpression>
<groupHeader>
<band/>
</groupHeader>
<groupFooter>
<band/>
</groupFooter>
</group>
<group name="jantina">
<groupExpression><![CDATA[$F{jantina}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="48" splitType="Stretch">
<staticText>
<reportElement x="237" y="10" width="100" height="20"/>
<textElement>
<font fontName="Arial" size="12"/>
</textElement>
<text><![CDATA[Penyata bulanan]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[negeri]]></text>
</staticText>
<staticText>
<reportElement x="79" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[jantina]]></text>
</staticText>
<staticText>
<reportElement x="158" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[bilmale]]></text>
</staticText>
<staticText>
<reportElement x="237" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[jds]]></text>
</staticText>
<staticText>
<reportElement x="316" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[percent]]></text>
</staticText>
<staticText>
<reportElement x="395" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[p_jdk]]></text>
</staticText>
<staticText>
<reportElement x="474" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<text><![CDATA[countstate]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{negeri}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="79" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{jantina}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="158" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{bilmale}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="237" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{jds}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="316" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{percent}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="395" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{p_jdk}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="474" y="0" width="79" height="20"/>
<textElement textAlignment="Center">
<font fontName="Arial"/>
</textElement>
<textFieldExpression class="java.lang.Long"><![CDATA[$F{countstate}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
The answer is i create the group and put this formula in
"Print When Expression" into field. That is new Boolean($V{negeri_COUNT}.intValue()==1)
and i uncheck "Print Repeated values "

How to sum all values in a column in Jaspersoft iReport Designer?

I have below similar report in Jaspersoft iReport Designer, but not able to figure out how to sum all values present in vertical column "Doctor Payment" to get a total of "1601"? Length of this columns is variable (i.e. no of rows vary according to size of database & its update frequency ).
Is there any variable like $V{COLUMN_COUNT} (actually gives no of rows, here 5),
which gives sum of all values in a column? If no, how to do sum?
Doctor ID Doctor Payment
A1 123
B1 223
C2 234
D3 678
D1 343
Total 1601
It is quite easy to solve your task. You should create and use a new variable for summing values of the "Doctor Payment" column.
In your case the variable can be declared like this:
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{payment}]]></variableExpression>
</variable>
the Calculation type is Sum;
the Reset type is Report;
the Variable expression is $F{payment}, where $F{payment} is the name of a field contains sum (Doctor Payment).
The working example.
CSV datasource:
doctor_id,payment
A1,123
B1,223
C2,234
D3,678
D1,343
The template:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ...>
<queryString>
<![CDATA[]]>
</queryString>
<field name="doctor_id" class="java.lang.String"/>
<field name="payment" class="java.lang.Integer"/>
<variable name="total" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{payment}]]></variableExpression>
</variable>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Doctor ID]]></text>
</staticText>
<staticText>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="10" isBold="true" isItalic="true"/>
</textElement>
<text><![CDATA[Doctor Payment]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement/>
<textFieldExpression><![CDATA[$F{doctor_id}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement/>
<textFieldExpression><![CDATA[$F{payment}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Total]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<box leftPadding="10"/>
<textElement>
<font isBold="true" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
The result will be:
You can find a lot of info in the JasperReports Ultimate Guide.
iReports Custom Fields for columns
(sum, average, etc)
Right-Click on Variables and click Create Variable
Click on the new variable
a. Notice the properties on the right
Rename the variable accordingly
Change the Value Class Name to the correct Data Type
a. You can search by clicking the 3 dots
Select the correct type of calculation
Change the Expression
a. Click the little icon
b. Select the column you are looking to do the calculation for
c. Click finish
Set Initial Value Expression to 0
Set the increment type to none
Leave Incrementer Factory Class Name blank
Set the Reset Type (usually report)
Drag a new Text Field to stage (Usually in Last Page Footer, or Column Footer)
Double Click the new Text Field
Clear the expression “Text Field”
Select the new variable
Click finish
Put the new text in a desirable position 

is it possible print element only when its detail band is the last on page?

Is it possible, to get a condition, that I can print an element only when its detail band is the last on page in Jasper Reports?
We can have variable saying record number on the page. But how we get the calculated total record on each page?
This is done with the "reset type" on a variable
<?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="report1" language="groovy" pageWidth="612" pageHeight="792" columnWidth="612" leftMargin="0" rightMargin="0" topMargin="10" bottomMargin="10" uuid="39852bd8-6125-4359-8d76-06927e7be492">
<queryString>
<![CDATA[SELECT ROWNUM N FROM dual CONNECT BY LEVEL <= 200 ]]>
</queryString>
<field name="N" class="java.math.BigDecimal"/>
<variable name="N_count_page" class="java.lang.Integer" resetType="Page" calculation="Count">
<variableExpression><![CDATA[$F{N}]]></variableExpression>
</variable>
<variable name="N_count_report" class="java.lang.Integer" calculation="Count">
<variableExpression><![CDATA[$F{N}]]></variableExpression>
</variable>
<title>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="93284d9f-1ee0-4a15-b227-31b55aa2e48b" x="0" y="0" width="376" height="20"/>
<textElement textAlignment="Center">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Page Count"]]></textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="20">
<staticText>
<reportElement uuid="a7113fdd-591b-4fee-9123-981ab75c6fa6" mode="Opaque" x="0" y="0" width="100" height="20" forecolor="#FFFFFF" backcolor="#000000"/>
<textElement/>
<text><![CDATA[N]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement uuid="54bac746-4efb-4412-81bc-b4ba807c60fd" x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{N}]]></textFieldExpression>
</textField>
</band>
</detail>
<pageFooter>
<band height="50">
<staticText>
<reportElement uuid="4c685263-0ef7-4a68-a328-39901ef2806f" x="0" y="0" width="100" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Rows on page :]]></text>
</staticText>
<textField>
<reportElement uuid="c65214f1-82dc-476a-8439-087854bbc5c6" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{N_count_page}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="48b37aff-b169-4ca2-b9dd-30c026988f68" x="289" y="30" width="80" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement uuid="983ccfed-d783-429e-bc6c-3fa488b2e106" x="369" y="30" width="40" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<lastPageFooter>
<band height="64">
<staticText>
<reportElement uuid="240e2f86-991a-4fc1-941b-56cc43b28c25" x="0" y="24" width="100" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Rows on report :]]></text>
</staticText>
<textField>
<reportElement uuid="718d4481-4716-4071-9989-27d5119fb428" x="100" y="24" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{N_count_report}]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement uuid="f03359be-3bbe-4da8-9bd8-ac024aa6f289" x="369" y="44" width="40" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="ad4aa2c0-9ad8-4892-a16f-0bb584c93916" x="289" y="44" width="80" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="b4bdd29a-4ef9-46cc-a57a-df7577bdd73f" x="0" y="0" width="100" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Rows on page :]]></text>
</staticText>
<textField>
<reportElement uuid="39952747-170c-4747-8e2c-0e12ab608ae9" x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{N_count_page}]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>

Printing serial number in jasper report detail

I have created a jasper report. In that report in detail areaI have "serialNumber" column. That column wants to be auto incrementive and stats with "1". I am using hibernate for query.
Sample code is :
<detail>
<band height="17" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="12" y="0" width="27" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[serialNumber]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="51" y="0" width="37" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{date}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="138" y="0" width="75" height="15"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{time}]]>
</textFieldExpression>
</textField>
</band>
</detail>
Can anyone help to print serial number in jasper report.
Using variable we can achieve that.
Sample code :
<variable name="seraialNumber" class="java.lang.Integer" resetType="None"
calculation="Count"/>
Depends on the requirement we have to change expression
You have to bind the column to a bean which returns incrementing numbers.
You Can use alternate solution for this problem that build in Variable $V{REPORT_COUNT}.
This variable will return the row count in Integer format.
Sample Expression :
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>.
<variable name="serial number" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[0]]></variableExpression>
</variable>
I will show an image for better understanding