Friday, 4 April 2014

Tip - Playing with variable in report bands - Summation of a query column using variable in jasper iReport in Title, Column Header and other bands

Hi Guys,

This is very useful tip in jasper iReport to calculate the summation of query columns using variables. 

* This way of summation reduces the SQL/other language code to calculate the column summation with in it.  i.e., 
* Faster and simpler and easy understandable. 

* To sum the the SQL query column value, you just need to drag and drop the column field from Fields section of Palette. 

* When you drag and drop, the iReport engine in the back end creates variable with the properties.
  Find images 1 and 2 for the above point. 

* This way of drag and drop of column summations will work in Title band, Column Header,Footer, Page Header and Footer band. 

* The other way is you can directly create your own variable by specifying the properties which will not work in the Title, Column/Page Header/Footer bands but works  only in Summary band with Reset type change. 

You can find a different value in column footer & summary for own created variable. 

* So it is recommend to drag and drop when you need column summations in the bands.  









NOTE: 
* Even though if you give the same properties for your own variable it'll give Null value except in Summary band with Reset type change. 

* Also note that , the variable in Detail band will not work. Detail band will fall into loop(repetition) and this is the case you are finding summation value.(A single value). 

* Not checked with other Calculations while dragging and dropping but hope will work in the same way.

:-) :-) :-)

Sadakar 
Specialist in BI


1 comment:

  1. Hello,
    I am working on column summary.The values of the column field are java.math.Bigdecimal class type in Dataset query. In the sql db source it is string type.The variable I created in jasper is java.lang.Double class type. After i run I get is
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number

    I tried changing variable class type to java.lang.string and column class also to string and summed, output gives last value from the column. Whereas my output should be sum of all values in column. Can you help me?

    ReplyDelete