views:

710

answers:

1

I have a report in BIRT and I want to add a summary at the end.

The report is 3 tables that have there own dataset. I want to show a fourth table with the summary information an a grand total. I have trouble calculating the grand total.

ex:

DataSet #1
col1 | col 2 | Total
   x |     x |     x
   x |     x |     x
                  xx


DataSet #2
col1 | col 2 | Total
   x |     x |     x
   x |     x |     x
                  xx

DataSet #3
col1 | col 2 | Total
   x |     x |     x
   x |     x |     x
                  xx


Summary
Total DataSet #1 |  xx
Total DataSet #2 |  xx
Total DataSet #3 |  xx
Grand Total      | xxx
+2  A: 

You are already creating the necessary sub-totals in each of the first three tables (via a group I would guess). In the create scripting event for the table cell with your Grand Total, set a Persistent Global Variable to track each sub-total. You can then access each value inside the fourth and final table.

To set the variable:

var totalValue = this.getDataRowData().getColumnValue("totalColumnName");
reportContext.setPersistentGlbalVariable("DataSet1Total", totalValue.toString());

NOTE: You will need to send the grand total to a "String" type to ensure serialization. You can convert it back to a number when you render the final summary table.

To use the variable, add a Text control to your report (in a cell on the Summary Table). In the onCreate scripting event for the text control enter the following:

this.text = reportContext.getPersistentGlobalVariable("DataSet1Total");

You would do this for each summary field you retained earlier. Then for the Grand total, you can do this:

this.text = parseInt(getPersistentGlobalVariable("DataSet1Total")) + parseInt(getPersistentGlobalVariable("DataSet2Total")) + parseInt(getPersistentGlobalVariable("DataSet3Total"));

A Persistent Global Variable is simply a serializable value that can be accessed across component boundaries inside a report. It can come in very handy for requirements just like yours.

Good Luck!

MystikSpiral
I tried doing this and it does not seem to work. My dataset totals are table aggregates (SUM function) - the field is in the footer. I tried adding the code in the Render method of the table that does not seem to work. I tried adding it to the Render method on the text field in the footer and that too does not work.Any suggestions on what I might be doing wrong/ how to fix it is welcome
shikarishambu