Mahi Mali
Mahi Mali

Reputation: 37

How to create user defined formula for user defined field

I have created one JasperReports report in iReport 4.5.0.

Here i have created one expression as:

<textField pattern="###0.0;-###0.0">
            <reportElement x="248" y="3" width="46" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[( $F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) )]]></textFieldExpression>
</textField>

Here I need the sum(total) of this text field created above ,

How to do that?

Upvotes: 0

Views: 1500

Answers (1)

Israel Lopez
Israel Lopez

Reputation: 1145

In this case you would simply create a variable with the same expression, but with a operation of "SUM". You can change the reset type to specify a group or simply for the whole report.

You can then use that variable in the Text Field element, with the execution time of Report/Group/Now depending on your needs.

<variable name="SOSUM" class="java.lang.Double" calculation="Sum">
    <variableExpression><![CDATA[$F{salesdetails_LessWeight} == 0 ? $F{salesdetails_Weight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) : $F{salesdetails_WithPlasticWeight} - ($F{salesdetails_LessWeight} * $F{salesdetails_Quantity}) ]]></variableExpression>
</variable>

Upvotes: 1

Related Questions