How can I count or sum different strings


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.

Jason30's picture
Joined: Feb 9 2017 - 4:57am
Last seen: 1 month 5 days ago

2 Answers:


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. 

joseng62's picture
Joined: Dec 5 2014 - 2:43am
Last seen: 1 month 6 days ago

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.

Jason30's picture
Joined: Feb 9 2017 - 4:57am
Last seen: 1 month 5 days ago