0

In the jrxml, I want to be able to get TOTAL and AVERAGE of a large number of columns easily without explicitly writing variables for each of the columns like I have done for one of the columns in my report, as referred from this link. Any reference or a sample would be highly appreciated.

<variable name="total_unit1_kwh" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[ $F{unit1_kwh} ]]></variableExpression>
  </variable>

And, in summary,

<summary>
    <band height="32">
      <staticText>
        <reportElement x="0" y="0" width="40" height="16"/>
        <box bottomBorder="Thin" leftBorder="Thin" rightBorder="Thin" padding="2"/>
        <textElement textAlignment="Center">
          <font isBold="true" isItalic="true"/>
        </textElement>
        <text><![CDATA[Total]]></text>
      </staticText>

      <staticText>
        <reportElement x="0" y="16" width="40" height="16"/>
        <box bottomBorder="Thin" leftBorder="Thin" rightBorder="Thin" padding="2"/>
        <textElement textAlignment="Center">
          <font isBold="true" isItalic="true"/>
        </textElement>
        <text><![CDATA[Avg]]></text>
      </staticText>

      <textField pattern="#0.0">
        <reportElement x="40" y="0" width="50" height="16"/>
        <box bottomBorder="Thin" rightBorder="Thin" padding="2"/>
        <textElement textAlignment="Center">
          <font isBold="true"/>
        </textElement>
        <textFieldExpression><![CDATA[$V{total_unit1_kwh}]]></textFieldExpression>
      </textField>
   </summary>

The following image is to show the columns of which I need to get total and average.

Large columned

Community
  • 1
  • 1
hlkstuv_23900
  • 864
  • 20
  • 34

1 Answers1

0

I am afraid that there is no easier way how to do it than writing variables for each column and total/average value. The only possible option how to do in another way is to make Totals and averages in database and [UNION][1] it at the end of your query, but this should be probably very bad option.

I recommend stay with variables. May be it is longer to write, but it works correctly and in the right way.

droben
  • 89
  • 8