I have JasperReport's sub_employment with a SubReport sub_salary I'd like to sum the return values from the SubReport.
This works, but the sum ignore the last record.
See the result PDF

I'd tried every possibility from "evaluation time" and "reset type"
Variable
<variable name="ACTUAL_HOURS" class="java.lang.Double" resetType="Column" calculation="Sum">
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ACTUAL_SALARY" class="java.lang.Double" resetType="Column" calculation="Sum">
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ACTUAL_SALARY_MONTH" class="java.lang.Double" resetType="Column" calculation="Sum">
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_HOURS" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{ACTUAL_HOURS}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_SALARY" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{ACTUAL_SALARY}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{ACTUAL_SALARY_MONTH}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
<variable name="ENTRY_DATE" class="java.util.Date" calculation="Lowest">
<variableExpression><![CDATA[$F{entry_date}]]></variableExpression>
</variable>
<variable name="BUSINESS_FUNCTION" class="java.lang.String">
<variableExpression><![CDATA[$F{business_function}]]></variableExpression>
</variable>
Band:
<band height="14">
<printWhenExpression><![CDATA[$V{IS_VALID}]]></printWhenExpression>
<subreport>
<reportElement x="0" y="0" width="489" height="14" isRemoveLineWhenBlank="true" uuid="0b445260-50f1-4a00-bd12-b278d3d18ec1"/>
<subreportParameter name="REPORT_RESOURCE_BUNDLE">
<subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="OWNER">
<subreportParameterExpression><![CDATA[$P{OWNER}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="PRODUCT_NAME">
<subreportParameterExpression><![CDATA[$P{PRODUCT_NAME}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="COPYRIGHT">
<subreportParameterExpression><![CDATA[$P{COPYRIGHT}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="USER">
<subreportParameterExpression><![CDATA[$P{USER}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="USER_FIRSTNAME">
<subreportParameterExpression><![CDATA[$P{USER_FIRSTNAME}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="USER_LASTNAME">
<subreportParameterExpression><![CDATA[$P{USER_LASTNAME}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="USER_EMAIL">
<subreportParameterExpression><![CDATA[$P{USER_EMAIL}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="USER_NAME">
<subreportParameterExpression><![CDATA[$P{USER_NAME}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="EMPLOYEE_ABBREVIATION">
<subreportParameterExpression><![CDATA[$P{EMPLOYEE_ABBREVIATION}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="REPORT_NAME">
<subreportParameterExpression><![CDATA[$P{REPORT_NAME}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="PRINT_DATE">
<subreportParameterExpression><![CDATA[$P{PRINT_DATE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="VALID_DATE">
<subreportParameterExpression><![CDATA[$P{VALID_DATE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="SHOW_EMPLOYMENT_TOTAL">
<subreportParameterExpression><![CDATA[$P{SHOW_EMPLOYMENT_TOTAL}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="ROUND_SALARY_MONTH_SINGLE">
<subreportParameterExpression><![CDATA[$P{ROUND_SALARY_MONTH_SINGLE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="ROUND_SALARY_YEAR_TOTAL">
<subreportParameterExpression><![CDATA[$P{ROUND_SALARY_YEAR_TOTAL}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="ROUND_SALARY_YEAR_SINGLE">
<subreportParameterExpression><![CDATA[$P{ROUND_SALARY_YEAR_SINGLE}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="ROUND_SALARY_MONTH_TOTAL">
<subreportParameterExpression><![CDATA[$P{ROUND_SALARY_MONTH_TOTAL}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$F{hr_employment\$hr_employee_salary}]]></dataSourceExpression>
<returnValue subreportVariable="SUM_ACTUAL_SALARY_MONTH" toVariable="ACTUAL_SALARY_MONTH"/>
<returnValue subreportVariable="SUM_ACTUAL_SALARY" toVariable="ACTUAL_SALARY"/>
<returnValue subreportVariable="SUM_ACTUAL_HOURS" toVariable="ACTUAL_HOURS"/>
<subreportExpression><![CDATA["sub_salary.jasper"]]></subreportExpression>
</subreport>
</band>
Summary
<summary>
<band height="15">
<textField>
<reportElement x="0" y="1" width="150" height="14" uuid="79b0b8d3-e91d-4b24-81fe-b40c16934fd8"/>
<textElement verticalAlignment="Middle">
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA["Total"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement style="label-W-B-L" x="360" y="1" width="70" height="14" uuid="747fd18d-4afe-4343-bd66-ee8897309e59"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY_MONTH}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement style="label-W-B-L" x="255" y="1" width="35" height="14" uuid="01a90af5-5fec-42e5-a69e-be21f034b51b"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$V{SUM_ACTUAL_HOURS}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement style="label-W-B-L" x="290" y="1" width="70" height="14" uuid="7dfc669e-3d34-4aa0-afc0-b9be20db5a7a"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="0" width="489" height="1" uuid="f7997151-3c20-4e44-b574-c07709f3b35f"/>
<graphicElement>
<pen lineWidth="1.0"/>
</graphicElement>
</line>
</band>
</summary>
Yes, this way the calculation of the variable
<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$V{ACTUAL_SALARY_MONTH}]]></variableExpression>
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
is done before the $V{ACTUAL_SALARY_MONTH} is returned from the sub-report.
You have multiple solutions:
textField $V{SUM_ACTUAL_SALARY_MONTH}.doubleValue()+$V{ACTUAL_SALARY_MONTH}.doubleValue()
The textField expression would be:
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement style="label-W-B-L" x="255" y="1" width="35" height="14" uuid="01a90af5-5fec-42e5-a69e-be21f034b51b"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="10"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$V{SUM_ACTUAL_SALARY_MONTH}.doubleValue()+$V{ACTUAL_SALARY_MONTH}.doubleValue()]]></textFieldExpression>
</textField>
NOTE: The variable ACTUAL_SALARY_MONTH return value from subreport should not have calculation and resetType.
<variable name="ACTUAL_SALARY_MONTH" class="java.lang.Double">
<initialValueExpression><![CDATA[new Double(0.0)]]></initialValueExpression>
</variable>
The main variable needs to have calculation System
no calculation is done and the expression is not evaluated, the value of this variable will be the last value set on it. Useful to store partial results or the final result of a computation.
Main variable
<variable name="SUM_ACTUAL_SALARY_MONTH" class="java.lang.Double" calculation="System"/>
Sub report return value
<returnValue subreportVariable="SUM_ACTUAL_SALARY" toVariable="SUM_ACTUAL_SALARY_MONTH" calculation="Sum"/>
Note: How calculation="Sum" is used on returnValue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With