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

count number of occurence in a variable


sonya14ab

Recommended Posts

Hello.

I'm  using ireport 4.1.1. I created a variable $V{correpondance}, the value of this variable is a the string  "conforme" or the string "non conforme" according to a condition.

Now the problem is that i want to create a chart with two slices that shows the total number of fields  "conforme" and the fields "non conforme". I tried to create a groupe (count) and a variable $V{X} with these properties: 

class: java.lang.integer,  calculation:count, resettype: repot, incrementtype: group, incrementgroup: count, variable expression: $V{count_COUNT}++ 

and set the chart key expression to  $V{correpondance} and the value expression to $V{X} but the chart is not showing the right values.

could anyone help me to solve this problem?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

I had a similar problem, and something like this worked for me:

Create a variable, called something like $V{conforme_counter}, integer class, no calculation function, with expression:

IF(EQUALS($V{correpondance}, "conforme"),1,0)...so if $V{correpondance} is "conforme", then $V{conforme_counter} has value 1, else 0.

Then create another variable, called something like $V{conforme_counter_sum}, integer class, SUM calculation function, with expression:

$V{conforme_counter}....this will add up all the 1s, giving you the number of "conforme" occurrences.

Similarly, create another variable, $V{non_conforme_counter}, integer class, no calculation function, with expression:

IF(EQUALS($V{correpondance}, "non conforme"),1,0)...so if $V{correpondance} is "non conforme", then $V{non_conforme_counter} has value 1, else 0.

Then, create $V{non_conforme_counter_sum}  integer class, SUM calculation function, with expression:

$V{non_conforme_counter}....this will add up all the 1s, giving you the number of "non conforme" occurrences.

Then, in your chart (I'm assuming it's a bar chart), you'll have to create two separate series. The first you can call "conforme", and the value expression will simply be

$V{conforme_counter_sum};

the second series you can call "non conforme", and its value expression will be $V{non_conforme_counter}.

This may be possible without the use of the $V{correpondance} variable; you can key your conforme/non-conforme conditions directly into the "IF" expressions above.

Hope this helps!

M.B.Morgan

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