Variable that displays a total for the column

Dima-A
2004-09-28
2013-04-25
  • Dima-A
    Dima-A
    2004-09-28

    Hello all,

    I'm new to JasperReports, so maybe this is trivial..

    Here are a few questions I have:

    1. How to make a variable that displays a total for the column work..

    The problem:

    I have a working simple jasper report that just selects columns from the DB (MySQL) it displays all rows of the table..

    Now I'd like to be able to have totals at the bottom of each column.

    I've added a variable the does summation.. The variable is being populated, but it repeats after each row and I get to see a running total sum which I don't want..  How do I make it appear JUST once at the bottom of the column..

    I was trying to place this variable into the "Column Footer" section.. with the following problem:

    1. it appears at the bottom of the page..  not immediatelly following the colomn..

    Again, I'm sure this must be something trivial, please help...

    Regards...

    I'm attaching the report code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

    <jasperReport name="AssetClassMonthlySummary" pageWidth="702" pageHeight="851" columnWidth="662" columnSpacing="15" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
        <queryString><![CDATA[select * from Trade_Hist_AssetClass_Report]]></queryString>
        <field name="AssetClass" class="java.lang.String">
        </field>
        <field name="Commisions" class="java.lang.Double">
        </field>
        <field name="TransMonth" class="java.lang.Double">
        </field>
        <field name="TransDay" class="java.lang.Double">
        </field>
        <field name="TotalValueMonth" class="java.lang.Double">
        </field>
        <field name="TotalValueDay" class="java.lang.Double">
        </field>
        <field name="LrgSingleTrade" class="java.lang.Double">
        </field>
        <variable name="TotalTransSum" class="java.lang.Double" calculation="Sum">
            <variableExpression><![CDATA[$F{TransMonth}]]></variableExpression>
        </variable>
        <title>
            <band height="50">
                <staticText>
                    <reportElement positionType="Float" mode="Opaque" x="0" y="-6" width="841" height="49"/>
                    <textElement>
                        <font size="16" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Transaction Tracking And revenue Monthly Report
                         "Decemeber 2004"]]></text>
                </staticText>
            </band>
        </title>
        <pageHeader>
            <band height="38">
            </band>
        </pageHeader>
        <columnHeader>
            <band height="20">
                <staticText>
                    <reportElement positionType="Float" mode="Opaque" x="0" y="0" width="134" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Summary By Asset Class]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" mode="Opaque" x="140" y="0" width="70" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Commisions]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" mode="Opaque" x="216" y="0" width="108" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Transactions/Month]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" mode="Opaque" x="324" y="0" width="108" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Avg Transactions/Day]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" x="432" y="0" width="67" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Total Value/Month]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" x="502" y="0" width="84" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Avg Value/Day]]></text>
                </staticText>
                <staticText>
                    <reportElement positionType="Float" x="586" y="0" width="108" height="20"/>
                    <textElement>
                        <font isUnderline="true"/>
                    </textElement>
                    <text><![CDATA[Largest Trade]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="28">
                <textField>
                    <reportElement positionType="Float" mode="Opaque" x="0" y="0" width="129" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.String"><![CDATA[$F{AssetClass}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" mode="Opaque" x="138" y="0" width="64" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{Commisions}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="216" y="0" width="108" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{TransMonth}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="324" y="0" width="108" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{TransDay}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="430" y="0" width="69" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{TotalValueMonth}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="500" y="0" width="85" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{TotalValueDay}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="586" y="0" width="108" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$F{LrgSingleTrade}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement positionType="Float" x="215" y="40" width="0" height="0"/>
                    <textElement/>
                    <text><![CDATA[static text]]></text>
                </staticText>
            </band>
        </detail>
        <columnFooter>
            <band height="53" isSplitAllowed="false">
                <staticText>
                    <reportElement positionType="Float" isPrintRepeatedValues="false" mode="Opaque" x="124" y="6" width="47" height="24" isPrintWhenDetailOverflows="true"/>
                    <textElement>
                        <font isBold="true"/>
                    </textElement>
                    <text><![CDATA[Total $]]></text>
                </staticText>
                <textField>
                    <reportElement positionType="Float" x="225" y="20" width="0" height="0"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.String"><![CDATA["text field"]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" x="225" y="20" width="0" height="0"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.String"><![CDATA["text field"]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement positionType="Float" isPrintRepeatedValues="false" mode="Opaque" x="212" y="10" width="119" height="21"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Double"><![CDATA[$V{TotalTransSum}]]></textFieldExpression>
                </textField>
            </band>
        </columnFooter>
        <pageFooter>
            <band height="42">
                <staticText>
                    <reportElement positionType="Float" x="0" y="0" width="40" height="15"/>
                    <textElement/>
                    <text><![CDATA[Page:]]></text>
                </staticText>
                <textField>
                    <reportElement positionType="Float" x="40" y="0" width="100" height="15"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>
            </band>
        </pageFooter>
        <summary>
            <band>
            </band>
        </summary>
    </jasperReport>

     
    • Andy Feltmate
      Andy Feltmate
      2006-03-17

      Did you get this to work (and are you using iReports or OR Designer)?

      I'm trying to do something similar.