Jump to content
Changes to the Jaspersoft community edition download ×

Jasper Report group variable sum returns incorrect value


Recommended Posts

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>


        <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

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

On 4/19/2024 at 3:27 PM, fr4d1s said:

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>


        <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

Reset type and Increment type and Evolution is the main character in variable which only solve the issue.   try to set reset to none if that works then all good. otherwise share the jrxml to solve the issue. or you can share group and there order and which group you are using. 

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