Jump to content
We've recently updated our Privacy Statement, available here ×

How to sum column totals?


2004 IR Help

Recommended Posts

By: betasics - betasics

How to sum column totals?

2005-02-28 14:31

I need use Jasper to create a report like:

 

Column1 Column2 Column3

----------------------------------------

Row1 1 3

Row2 3 5

--------------------------------------

Total 4 8

 

 

Row1 and Row2 are from the database.

 

How to print the total columns based on Row1 and Row2? Can Jasper sum the totals for each column? What is the expression look like?

 

By the way, I know I can use "GroupName_COUNT" variable to get the row count. I imagine there might be similar mechanism to calculate the column totals.

 

Your help is highly appreciated.

 

beta

 

 

 

 

 

 

By: Murali - murali_pagadala

RE: How to sum column totals?

2005-03-03 06:04

Hi

create a group first based on field like empno.

 

then create variable like

 

JRDesignVariable variable = new JRDesignVariable();

JRDesignExpression varInitExpression = new JRDesignExpression();

variable.setName( "salSum");

variable.setCalculation(JRVariable.CALCULATION_SUM);

variable.setValueClassName( "java.lang.Double);

variable.setResetType(JRVariable.RESET_TYPE_GROUP);

 

varExpression.setText("new Integer( $F{Field_Name_To_Sum} )");

varExpression.setValueClassName("java.lang.Double");

varInitExpression.setText("new Double(0.0)");

varInitExpression.setValueClassName("java.lang.Double");

variable.setInitialValueExpression(varInitExpression);

variable.setExpression(varExpression);

//ADD THE GROUP TO UR VARIABLE

variable.setResetGroup( group );

jasperDesign.addVariable(variable);

 

IF U PERFECTY DEFINE THE GROUP IT WORKS FINE

 

Hope u got solution !

 

 

 

 

 

 

 

By: Stan Berka - stanberka

RE: How to sum column totals?

2005-03-04 15:48

The code above does look complex. But if you use iReport (and it's quite simple to learn it; it took me 4 hours max to install it and learn), you follow these steps:

* Add a group: there you will specify the expression you want to group by.

* Add a new variable: specify ResetType=group and select the group you added above. For the CallculationType set 'sum'. For the default value set: new Integer(0) or whichever type you need for this total variable.

* Insert a field with an expression: String.valueOf(${your_total_variable}) in the footer for this group (it's added when you add a group)

 

Enjoy. It's simple.

Stan Berka

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...