Jump to content

How can I count or sum different strings


Recommended Posts

Hi all,

I wonder how to count different values.

Example output of the table in the group band:

Row 1:

  1. Cat 1: 4
  2. Cat 2: 3
  3. Cat 3: 3

Row 2:

  1. Cat 1: 1
  2. Cat 2: 2
  3. Cat 3: 1

Then I want to put the total in the last page footer: 14

Note: There could alse be 3 rows, or 4.

Thanks in advance for any help / insights.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You need to be more specific and clear on this. 
Is the value "1. Cat 1:1" the whole value a string or are they broken up in 4 columns. 

At end of day you would need to create a variable and use the calculation function to count of sum. 
Then depending on how you want to count or sum, you need to create group and use the correct bands. 
Then you need to select the increment type and Reset type. 
Can also create multiple variables with different groupings, increment types and Reset types and then count sum these together. 

If you want to use the last value in your   "1. Cat 1:1" value, you can use subring methods to get last value and then convert the value to integer and then count or sum. 
One can also create REgex jar custom, so you can use a regex methods to get the required value, then convert type, then count or sum.
Many ways, it just depends on how you want to do it. 

Link to comment
Share on other sites

Thanks for your reaction Joseng.

Sorry for the indistinctness.

The value is a calculated field.

So in the example there are 6 values (3 in row 1 + 3 in row 2)

On the end I want to sum all 6 calculated values.

I am new to Jaspersoft, but coding wise I try to achieve something like this:

In the group (hidden?):

  • $variable1 = 4
  • $variable2 = 3
  • $variable3 = 3
  • $variable4 = 1
  • $variable5 = 2
  • $variable6 = 1

Page footer contains:

$total = $variable1+$variable2+$variable3+$variable4+$variable5+$variable6;

Hopefully this makes it more clearly.

Thanks again.

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