Jump to content
JasperReports Library 7.0 is now available ×

Counting field occurrence with a variable


Dduffek

Recommended Posts

Hi.

 

I have a report that will be have rows of data and captions. I don't know how many rows of data will exist, but I want to place a bar after every 2 caption rows. I have a field that can tell me if a row is a caption or a data, and I can handle placing the bar, if I know how many captions I have printed up to that point.

 

 

What I need to figure out is how to keep track of the number of captions that have been printed. I think I need a variable, but I am unsure of how to format the variable.

 

I think I need something similar to this:

Code:
<variable name="CaptionCount" class="java.lang.Integer" resetType="Report" calculation="Count">
variableExpression><![CDATA[($F{Type}.equals("caption"«»)? increment count: do nothing)]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
</variable>

 

Anyone have any ideas? Thanks for any thoughts you might have.

 

Duffek

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

calculation="Count" counts all the not-null values, therefore you need

Code:
<variable name="CaptionCount" class="java.lang.Integer" resetType="Report" calculation="Count">
<variableExpression><![CDATA[($F{Type}.equals("caption"«»)? "count me" : null)]]></variableExpression>
</variable>

 

You can also use Sum

Code:
[code]<variable name="CaptionCount" class="java.lang.Integer" resetType="Report" calculation="Sum">
<variableExpression><![CDATA[($F{Type}.equals("caption"«»)? new Integer(1) : new Integer(0))]]></variableExpression>
</variable>

 

HTH,

Lucian

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