1

I am using iReport 3.6.2 to build reports. I need to build a report that displays the total of each package. My sql query returns the below results.

**PackName---------PackCount**

pack1 --------------   4

pack2 --------------   3

pack1 --------------   1

pack3 --------------   3

pack2 --------------   3

pack1 --------------   2

My report needs to group the PackName and add the related PackCount like the below example

**Package Name ------------ Total**

pack1 ---------------------- 7

pack2 ---------------------- 6

pack3 ---------------------- 3

I've got my groupingCode as below

<variable name="PacksCountSum" class="java.lang.Integer" incrementType="Group" incrementGroup="packsGroup" calculation="Sum">
    <variableExpression><![CDATA[$F{packCount}]]></variableExpression>

</variable>
<group name="packsGroup">
    <groupExpression><![CDATA[$F{packName}]]></groupExpression>
    <groupHeader>
        <band height="20">
            <textField>
                <reportElement mode="Opaque" x="0" y="5" width="515" height="15" backcolor="#C0C0C0"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{packName}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="460" y="1" width="30" height="15"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PacksCountSum}]]></textFieldExpression>
            </textField>
        </band>
    </groupHeader>
</group>

But my results is being displayed as below

**Package Name ------------ Total**

pack2 ---------------------- null

pack1 ---------------------- 3

pack2 ---------------------- 8

pack3 ---------------------- 10

Could any one please assist me and guide me in the right direction. I cannot seem to find where my mistake is.

Alex K
  • 22,315
  • 19
  • 108
  • 236
R3LL1K
  • 21
  • 4

1 Answers1

0

I seemed to have solved my issue. I followed the example on Grouping records in JasperReports and it helped me with my grouping. I also added an "order by" in my SQL query to ensure my packNames are ordered.

Community
  • 1
  • 1
R3LL1K
  • 21
  • 4