Jump to content
Changes to the Jaspersoft community edition download ×

Adding two data elements


Recommended Posts



I want to add two fields like x and Y. What I did is using expresion as follows


$P{DataElement:Third Antenatal Visit}+$P{DataElement:Second Antenatal Visit}


But this gives me just the value of each data elemen together like 12 if the value of data element1 is 1 and if the value of dataelement2 is 2.



How can I Add two values of data element

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic


The fields you are adding are string fields.

To add the numeric value, you need to convert them to integers first, by using Java means.


The best way would be to make sure the fields themselves are integers in the database, and are thus assigned to Integer objects.

In the case of parameters, set their type to java.lang.Integer.


Then, using


should give a class cast exception, as the result is a Integer, and is cast to a String for printing;



should print the summed value.


If you cannot make the fields into Integer, you have to convert them before adding ...




Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...