Count number of rows where a specific fields value

0

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.

K.S.'s picture
8
Joined: Sep 10 2014 - 6:14pm
Last seen: 1 year 4 months ago

5 Answers:

0

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.

hozawa's picture
51078
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
0

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?

K.S.'s picture
8
Joined: Sep 10 2014 - 6:14pm
Last seen: 1 year 4 months ago
0

Did you set the initial value?

hozawa's picture
51078
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
1

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.

zh3ntil's picture
531
Joined: Nov 19 2014 - 11:02pm
Last seen: 3 years 3 months ago
0

I found a solution. I added a variable to a group and in TextField pointed out Group Changes [GroupName] and it worked.

K.S.'s picture
8
Joined: Sep 10 2014 - 6:14pm
Last seen: 1 year 4 months ago
Feedback
randomness