Question

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
Was it helpful?

Solution

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(reportContext.getPersistentGlobalVariable("DataSet1Total")) + parseInt(reportContext.getPersistentGlobalVariable("DataSet2Total")) + parseInt(reportContext.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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top