svenn Posted July 25, 2007 Share Posted July 25, 2007 Is there a way in iReport to exclude zeros from the value when calculating the Average for a variable? I have a column that I want to calculate the average for. The problem is that I want to exclude all items that are zero ie only base the calculation on the rows that have a value great then zero. Is there a way to do this? I set up a variable with the Calculation type set the Average. i can not see a way of excluding the zeros from the calculation. Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 25, 2007 Share Posted July 25, 2007 The only way that I can think of would be to exclude zero values from your query.For example if you are using SQL, you can use a CASE statement inside of your query to disregard zero values. One other possibility is to put a ternary expression in the variable's initial expresssion: $F{fieldname}.equals(0) ? $F{fieldname}= $F{fieldname} + 1 : $F{fieldname} I would try using the 'CASE' statement first though, it seems more practical. Hope this helps. Link to comment Share on other sites More sharing options...
svenn Posted July 26, 2007 Author Share Posted July 26, 2007 The solution end up being a simple one. In my variable expression I put the following ( $F{<my value>} <= 0 ? null : $F{<my value>} ) Now the average only includes the values greater then zero. Link to comment Share on other sites More sharing options...
bklawans Posted July 27, 2007 Share Posted July 27, 2007 svenn wrote:The solution end up being a simple one. In my variable expression I put the following( $F{<my value>} <= 0 ? null : $F{<my value>} )Now the average only includes the values greater then zero. That's the trick I usually use, but replace the "<=" with "!=" if you want to include negative values in the average. -Barry Link to comment Share on other sites More sharing options...
carlthewinner Posted June 9, 2010 Share Posted June 9, 2010 Thanks svenn, this is exactly what I needed to do! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now