jasper-reports

Jasper Report group variable sum returns incorrect value


In my report produced with Tibco Jaspersoft 6.3 I am facing a strange issue. I have a datasource as follows:

order_number - fiscal code - price - region_id

records can have the same order_number, as follows:

1 - xxyyzz - 10$ - 001

1 - mmnnxx - 5$  - 001

2 - kkhhff - 6$  - 001

3 - ppookk - 7$  - 001

1 - aayyzz - 10$ - 002

2 - llnnxx - 5$  - 002

2 - oohhff - 6$  - 002

2 - vvookk - 7$  - 002

for each group of records with the same order_number, I have a variable that calculates a value called ticket_value with an expression. This calculation works correctly, I see the right values for each order_number.

I have sum variables for price and ticket_value based on region.

I've created two groups, one for the region_id and one for order_number. I perform the calculation of the single ticket_value in footer of order_number group and the sums of prices and ticket_values for each region in the region_id footer.

The price sum value is correct for each region_id, but I don't have the correct value of the sum of ticket_value for each region_id and I don't understand where is the error in the variables configuration.

Here is the definition of variables used:

<variable name="ticket_somma_numero_ordine" class="java.lang.Double" resetType="Group" resetGroup="Gruppo_NUMERO_ORDINE">
        <variableExpression><![CDATA[$V{totale_importo_numero_ordine}.compareTo(new BigDecimal(36.15)) > 0 ? 36.15 : $V{totale_importo_numero_ordine}.doubleValue()]]></variableExpression>
    <variable name="sommatoria_ticket" class="java.lang.Double" resetType="Group" resetGroup="Gruppo_REGIONE" incrementType="Group" incrementGroup="Gruppo_NUMERO_ORDINE">
        <variableExpression><![CDATA[$V{sommatoria_ticket} + $V{ticket_somma_numero_ordine}]]></variableExpression>
        <initialValueExpression><![CDATA[0.0]]></initialValueExpression>
    </variable>

EDIT:

I've noticed that the sum variable sommatoria_ticket is wrong with this logic: looking at data example above, there are two records with order_number = 1 for the region_id = 1; in that case the value of sommatoria_ticket is doubled; if the records are 3, the value is x3...

It seems that the ticket_value calculation is shown just once per subgroup but it is taken for each row of the subgroup when the sommatoria_ticket variable is calculated.

I've tried to change increment type and reset type of variables, and also the evaluation time of the text fields, but the issue is not solved


Solution

  • I've solved it on my own this way: