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

Need help with subtraction variable


juser73

Recommended Posts

So i have a report that includes, username, employee number, sum of hours(for each employee), and difference of average hours...

I have a parameter so you can select which dates you want to view the employee hours

At the end of the report i have the average of total hours '$V{sum_5}' for the time period selectd (i.e. 5/01/2010-5/02/2010)

I want the difference of average hours to display if each individual employee worked above or below the total average hours and what that difference is...

 

For the variable i created i create a variable '$V{SUM}' which is equl to the individual hours for each employee..

Then i created another variable '$V{aboveave}' which is supposed equal the hours for each individual employee - the total average hours for the selected dates, so I put the variable expression to... '$V{SUM}.subtract( $V{sum_5} )'

 

But when I click preview the differences are all wrong and im not sure where the report is getting the information from, here's an example from my report (its only part of the report, but the average is correct for the entire report)...

 

username     employee number      sum of hours       difference of hours

user1                       a1                           3.00                    0.00

user2                        b2                           6.00                    1.50

user3                       c3                           .67                        -3.53

user4                       d4                            9.16                     4.01

                                                                                               average of all hours: 5.15



Post Edited by juser73 at 08/17/2010 19:03
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

you need only one variable that makes an average of worked hours.

suppose we call it

$V{avg_hours}

 

then, if you want to show the difference between the single employee hours ($F{HOURS}) and this average value ($V{avg_hours}), create a textfield with BigDecimal type putting this expression (equal to the expression you use)

$F{HOURS}.subtract($V{avg_hours} )

then set the evaluation time to AUTO.

in this way it works.

when you set the evaluation time to NOW (as you make) simply the JasperReport core makes a difference between the value of employee hours and the average calculated at this point of report...

so for the first one the average is 3... 3-3 =0
for the second is 3+6=9  /2=4,5   6-4,5=1,5
and so on...

give us feedback...

________________________________________

if it works... give me KARMA points please!    : ) 
_________________________________________

listening:  Stereolab- Emperor Tomato Ketch



Post Edited by slow at 08/18/2010 09:59
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...