Jump to content

HELP: Summing up group variables


2004 IR Help

Recommended Posts

By: wollin - wollin

HELP: Summing up group variables

2005-06-27 01:07

Hi,

I have some trouble summing up variables calculated (and reset) within a group.<br>My group variables are:<br>

$V{subtotal} = sum($F{amount}), reset type 'Group'<br>

$V{rounded_subtotal} = $V{subtotal}.setScale(0, BigDecimal.ROUND_HALF_UP).setScale(2), reset type 'Group'<br>

Question: How can I sum up all rounded_subtotals and display the the result at the end of the report?<br>

I tried to introduce:<br>

$V{rounded_total} = sum($V{rounded_subtotal}, reset type 'Report'<br>

but this gave me more or less arbitraty values of the rounded_total.<br>

Thanks for any suggestions<br>

/wn

 

 

 

 

By: Teodor Danciu - teodord

RE: HELP: Summing up group variables

2005-06-27 08:42

 

Hi,

 

It seems to me you need to increment the rounder_total

from group break to group break.

And this can be done using incrementType="Group"

and incrementGroup="YourGroup" for the "rounded_total"

variable.

 

Take a look at the CityNumber variable in the "datasource"

sample provided.

 

I hope this helps.

Teodor

 

 

 

 

 

By: wollin - wollin

RE: HELP: Summing up group variables

2005-06-28 02:53

Hi Teodor,

thanks for the feedback. After upgrading to 0.6.8 and jasperassistant to 1.5.5 I also realized these new attributes and implemented them, since they seemed to make sense. Unfortunately though they didn't solve the issue. I tried the following:

subtotals group footer:

$V{subtotal} = sum($F{amount})

$V{rounded_subtotal} = $V{subtotal}.setScale(0, BigDecimal.ROUND_HALF_UP).setScale(2)

 

report totals group footer:

$V{rounded_total} = $V{rounded_subtotal}, increment type and group as suggested by you, calculation = system.

 

The result is, that the rounded_total is always = the (rounded) sum of the details of the LAST group of the report, EXCLUDING the LAST detail of the last group.

Hard to explain, here are some examples:

 

Report has 1 group with a single detail:

rounded_total is zero.

 

Report has 1 group with 2 details:

rounded_total = rounded value of the FIRST detail.

 

Report has 1 group with 3 details:

rounded_total = rounded sum of FIRST and SECOND detail

 

Report has 2 or more groups:

Only the last group is taken into account for rounded_total with the systematics explained above.

 

Any ideas?

Thanks and regards

/wolfgang

 

 

 

 

 

 

By: Teodor Danciu - teodord

RE: HELP: Summing up group variables

2005-06-28 05:46

 

Hi,

 

Try the sample below. It contains a group that breaks

with every 5 records and sums up random BigDecimal

values.

You can fill it with JREmptyDataSource.

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

 

<jasperReport name="TestSumsReport" language="java" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">

<variable name="RandomBigDecimal" class="java.math.BigDecimal">

<variableExpression><![CDATA[new BigDecimal(100d * Math.random())]]></variableExpression>

</variable>

<variable name="Subtotal" class="java.math.BigDecimal" resetType="Group" resetGroup="TestGroup" calculation="Sum">

<variableExpression><![CDATA[$V{RandomBigDecimal}]]></variableExpression>

</variable>

<variable name="RoundedSubtotal" class="java.math.BigDecimal">

<variableExpression><![CDATA[$V{Subtotal}.setScale(0, BigDecimal.ROUND_HALF_UP).setScale(2)]]></variableExpression>

</variable>

<variable name="RoundedTotal" class="java.math.BigDecimal" incrementType="Group" incrementGroup="TestGroup" calculation="Sum">

<variableExpression><![CDATA[$V{RoundedSubtotal}]]></variableExpression>

</variable>

<group name="TestGroup">

<groupExpression><![CDATA[new Boolean($V{TestGroup_COUNT}.intValue() > 5)]]></groupExpression>

<groupFooter>

<band height="15">

<textField pattern="#0.0000">

<reportElement positionType="Float" x="100" y="0" width="100" height="15"/>

<textElement textAlignment="Right"/>

<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{Subtotal}]]></textFieldExpression>

</textField>

<textField pattern="#0.0000">

<reportElement positionType="Float" x="200" y="0" width="100" height="15"/>

<textElement textAlignment="Right"/>

<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{RoundedSubtotal}]]></textFieldExpression>

</textField>

<textField pattern="#0.0000">

<reportElement positionType="Float" x="300" y="0" width="100" height="15"/>

<textElement textAlignment="Right"/>

<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{RoundedTotal}]]></textFieldExpression>

</textField>

</band>

</groupFooter>

</group>

<detail>

<band height="15">

<textField pattern="#0.0000">

<reportElement positionType="Float" x="0" y="0" width="100" height="15"/>

<textElement textAlignment="Right"/>

<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{RandomBigDecimal}]]></textFieldExpression>

</textField>

</band>

</detail>

</jasperReport>

 

 

 

I hope this helps.

Teodor

 

 

 

 

 

By: wollin - wollin

RE: HELP: Summing up group variables

2005-06-28 07:24

Hi Teodor,

yes your example helped but - believe me - it drove me crazy. Finally the issue has been resolved. To make it short, please find next the reason why it didn't work in my setup, even though the configuration was more or less the same as provided in your example:

The variable RoundedTotal was defined BEFORE the variable RoundedSubtotal in my xml. Swap the variable definitions in your sample xml and you will surprisingly recognize, that the report preview shows WRONG values for RoundedTotal.

Obviously something the developer wouldn't expect, and not that easy to find and fix when working with jasperassistant designer instead of a normal text editor.

Thanks for your support and feedback

/wolfgang

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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