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

How to calculate a sum on report


jme14

Recommended Posts

I want to create some kind of timesheet with data of multiple employees. I have created a group on employee lastname.

 

To calculate a subtotal per employee I have created a variable V_SUM_PER_EMP:

- variable class type: java.math.BigDecimal

- calculation type: sum

- reset type: group

- reset group: lastname

- increment type: none

- variable expression: $F{minutes}

 

This works fine.

 

Now, I want to create a summary total to calculate the sum of all minutes for all employees on report. Therefore I can simply create another variable, like V_SUM_PER_EMP with reset group = report.

BUT in my report I want to compute the sum of minutes on report, based on variable V_SUM_PER_EMP (because in my real life report the variable expression of V_SUM_PER_EMP is more complex then in this example), so I created a new variable V_SUM_PER_EMP_REPORT:

- variable class type: java.math.BigDecimal

- calculation type: sum

- reset type: report

- reset group: -

- increment type: none

- variable expression: $V{V_SUM_PER_EMP}

 

The result value (printed in the summary band) of this calculation is NOT right.

 

The first group subtotal: 65.92

The second group subtotal: 22.42

The report total: 611.42

 

How can I calculate the right value?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

The reason this is occurring is because you are summing up a value that is a sum. As a result, you are summing the sum at each step. For example, if your first variable was v1 and the variable second v2, which summed of v1, you'd have:

 

v1 v2

0 0

2 2

2 4

7 11

-------

0 11

1 12

--------

0 12

3 15

 

Where the "--"'s represent new groups. As you can see v2 finishes off at 15 rather than your desired result of 11.

 

The direct solution is the one you suggested yourself, to create the second variable with the same variable expression as the first, but with a reset type of report. If this doesn't work due to your complex definition of the first variable, please post this complex expression, as we can't troubleshoot it blind.

Link to comment
Share on other sites

Thanks for you reply.

 

For each group, I calculate a subtotal with expression:

$V{v_sum_amount_1}.min( $V{v_sum_amount_2} ).multiply( $F{factor} )

 

this means:

subtotal := minimum(amount_1, amount_2) * factor

 

Example group:

a_1 a_2 charge

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

69,0 48,5 € 2.968,03

22,9 34,0 € 985,42

38,5 22,8 € 1.653,96

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

130,4 105,3 € 5.607,41 ==> € 4.527,90 (factor = 43)

 

This factor can be different per group (72.5 or 43)

amount_1 stands for the total hours per employee (130.4) in January 2008

amount_2 stands for the maximum amount to charge per employee (105,3) in January 2008

The subtotal value = min(130.4, 105.3) * 43 = 105.3 * 43 = 4527.90

 

So, I want to calculate the sum of $V{v_sum_amount_1}.min( $V{v_sum_amount_2} ).multiply( $F{factor} ) on report.

 

Any ideas?

 

Regards,

JanM

Link to comment
Share on other sites

  • 1 month later...

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