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

Correct Nested Group Count Behavior


2005 IR Help

Recommended Posts

By: Oliver Chua - oliverchua

Correct Nested Group Count Behavior

2004-10-27 02:08

I have a report that displays Employee's Expenses per Branch.

I have two groups defined: branch and employee.

For my employee footer, I show the sum of expenses for the employee, which works fine.

For my branch footer, I show the count of the number of employees in the branch with expenses.

 

For a branch that has only one employee with 2 expenses, using $V{branch_COUNT} should produce 1,

In my case, it prints out the number of records for that group: 2.

So, for a particular employee with 4 expenses records, the variable returns 4

Using ${REPORT_COUNT} also behaves the same way; it returns the record count of the report.

 

I'm not sure at all if it is the correct behavior.

 

In case it is the correct behavior, how can I get the count of employees and not the count of records of the particular branch?

Also, how can I get the count of employees for the whole company instead of the count of records of the report?

 

Thanks in advance

 

 

 

 

By: Oliver Chua - oliverchua

RE: Correct Nested Group Count Behavior

2004-11-02 19:11

Hi guys,

 

I'm still stumped with this problem. Hope somebody can help me out...

 

I've successfully got the number of employees with expenses for a particular branch by doing the ff.:

a. Declare variable named $V{employee_COUNT} with Reset Type "Group" and Reset Group "employee" and the initial value expression as...

($V{employee_COUNT} != null)?(new Integer($V{employee_COUNT}.intValue() + 1)):(new Integer(1))

b. Use a scriptlet that resets the count to 1 after every new branch. (I'm still not sure though, I thought it should be zero, but the result always is short by one, so I made it one).

public void afterGroupInit(String groupName) throws JRScriptletException

{

if ("branch".equals(groupName)){

System.out.println("in branch");

java.lang.Integer count=(java.lang.Integer)this.getVariableValue("employee_COUNT");

this.setVariableValue("employee_COUNT", new Integer(1));

}

}

c. Add a text field in the branch footer that displays $V{employee_COUNT}

 

My attempts to get the total number of employees with expenses company-wide include:

a. defining a variable named total_employee_COUNT that sums $V{employee_COUNT}, but the resulting number is much greater than the correct number.

b. modifying scriptlet above as:

public void afterGroupInit(String groupName) throws JRScriptletException

{

if ("branch".equals(groupName)){

System.out.println("in branch");

java.lang.Integer count=(java.lang.Integer)this.getVariableValue("employee_COUNT");

java.lang.Integer total=(java.lang.Integer)this.getVariableValue("total_employee_COUNT");

this.setVariableValue("total_employee_COUNT", new Integer(count.intValue()+total.intValue()));

this.setVariableValue("employee_COUNT", new Integer(1));

}

}

The number is smaller than the expected number.

 

Am I on the right track?

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