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

Count number of rows where a specific fields value


K.S.

Recommended Posts

Hi,

In JaspersoftStudio make a Jasperreport with 2 columns: Code (unique value field "code" for a certain period of time) and Total (how many times the value of the field "code" is repeated). 

I have a variable $V{CodeCount} with properties:

Variable class = java.lang.Integer

Calculation = Sum

ResetType = Column

Increment type = Column

Initial Value Expression = 0

Variable expression = $F{Code} != null ? 1 : 0

 

My result:

Code   Total

A         1

B         1

C         1

A         1

C         1

 

What I need:

Code   Total

A         2

B         1

C         2

How can I do it in Jasper without using sql? 

Thank you so much.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Why are you "summing" (Sum) instead of "counting" (Count)? I'm not sure why you havae an expression when you've set Count. Not sure why you've set Increment Type either. Also, do you have the list sorted by Code? It would be better if you've Grouped by Code, then you can just have Reset on Group Code.

Link to comment
Share on other sites

I found a solution to create Group Header and place there $FCode (i have result not A B C A C, and A B C), but I can not count how many times the value is repeated. 

I try to create Variable $V{Count_Code} with properties:

Variable class = java.lang.Integer

Calculation = Count

ResetType = [Groupname] Group

Increment type = None

but the column CountCode value is null. Why?

Link to comment
Share on other sites

Hi,

I assume that you use the variable on Group header, not on group footer. So you have to set the evaluation type of the textfield which is used for variable on table. Select the text field and go the properties. Under the 'Text Field' section, set the evaluation type as '[Groupname] Group' and try again. You should see the proper values.

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