How to use Initial Value Expression in Jasper Reports Studio to add value to only the first row?


My understanding of the initial value expression in Jasper Reports Studio is that it, the said value should be the first value. So I did set it to:

$F{rptran_units}.add(new BigDecimal(200))

and the expression for my variable to


and made my calculation sum.

This is because I want the first value of my variable expression to be have 200 added to it and subsequent values to continue summing without repeatedly adding 200. I guess I might not be going about it in the right way. I would appreciate some clarification on how I could achieve this using the initial value expression or any other method that would help me achieve my aim.


Yes you have slight misunderstanding what the initial value expression is used for, in your example it will not be used during the computation of the sum of $F{rptran_units}, it will only have that value before the computation of variable starts (first iteration of the detail band).

The initial value is:


the value assumed from the variable at the beginning, before the first computation of its expression - see <a href="http://community.jaspersoft.com/wiki/variables" rel="nofollow">Jasper Reports Variables</a>


but this does not mean that the variable start with this value if you like to compute a sum on a field, actually it is not passed to the compute engine and it will only be used if you use the variable (itself) in the expression as example $V{variable1}+5 in the above link

However the solution to your specific problem (add 200 to the current sum of $F{rptran_units}) is very simple, just add 200 to the variabile before displaying the value.


<textField> <reportElement x="0" y="0" width="100" height="30" uuid="d7a0eb2f-0664-46ec-91f1-02d6de303c18"/> <textFieldExpression><![CDATA[$V{SumOfRptran_units}.add(new BigDecimal(200))]]></textFieldExpression> </textField>

Another solution is to add another variabile that adds 200 to this variable and use this.

<variable name="SumAdd200" class="java.math.BigDecimal"> <variableExpression><![CDATA[$V{SumOfRptran_units}.add(new BigDecimal(200))]]></variableExpression> </variable>


  • Saving a large color image as `GTiff` with `gdal`
  • replacing spaces with just one “_”
  • Sending Emails from different accounts with Google App Script
  • Microsoft Collections for .NET [closed]
  • jQuery function to limit text entry based on word-count not working while pasting text
  • Add “Rubber Band” effect in android while changing background of application
  • Is it faster to create a new object reference if it will only be used twice?
  • How do I improve Rails / Paperclip image compression inside or ImageMagick / Rmagick?
  • Internet explorer 8 event fall through transparent parents
  • AJAX and Cross-Site Scripting to Read the Header
  • What to look for when setting UpdateBatchSize
  • Why is the 100*0.07 equal to 6.9999…? [duplicate]
  • SQL query comparing an attribute in multiple tuples based on values of another attribute within the
  • Better algorithm for if condition
  • FindAndModify, return array of Objects
  • Python importing a function with file's name contained in a variable
  • Subreport causing infinite loop
  • new spark.sql.shuffle.partitions value not used after checkpointing
  • Matching multiple strings to one long string using patterns
  • JFreeChart BarChart - Category Markers
  • SEO friendly 301 redirect .htm to .aspx
  • Can a Collections.shuffle be considered equivalent to a series of Randoms?
  • EntLib Way to Bind “Null” Value to Parameter
  • netsh acl setting (need alternative method - registry settings?)
  • how to set variables in a php include file?
  • Python pickle not one-to-one: different pickles give same object
  • Django model inheritance, filtering models
  • How do I include a SWC in an AS2 Flash project?
  • How to add a focus style to an editable ComboBox in WPF
  • How do I superscript characters in a UIButton?
  • Recording logins for password protected directories
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • Is possible to count alias result on mysql
  • Trying to switch camera back to front but getting exception
  • Benchmarking RAM performance - UWP and C#
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Programmatically clearing map cache
  • How to get NHibernate ISession to cache entity not retrieved by primary key