Reputation: 67
I want to add a variable to column footer of my table. It is the sum of the column values. eg: total sales, if column name is sales.
But when i try it it says variable not found for some reason. I have positioned the table in title band because if i put it in detail band the table repeats multiplied by the number of rows in the table. 5rows = 5pages with the same table.
Can someone please help me since im new to jasper and ireport.
I am using ireport 5.0.0
Thank you
Upvotes: 0
Views: 5620
Reputation: 3548
We always define variables at the center level so make sure if you are using any sub data-set for your table component, copy the same query in main report query area, then add a variable and change these properties in Ireport :-
Variable class :- java.lang.integer or java.math.BigDecimal
Calculation :- Sum
Variable expression:- $F{total_sales}
XML:- if you are not using Ireport
<variable name="total_sales" class="java.math.BigDecimal" calculation="Sum">
<variableExpression><![CDATA[$F{total_sales}]]></variableExpression>
</variable>
and after this you can use this variable for sum.
Upvotes: 1
Reputation: 300
Make sure you have this on your xml
<field name="total_column" class="java.lang.Long"/>
and have this as your text field expression
$F{total_column}
Change the name to whatever you are using.
Upvotes: 1