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

Exclude zero from variable average


svenn

Recommended Posts

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

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

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

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

  • 2 years 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...