. Adding different row values in Birt Report


You are creating a BIRT report and getting the selection of data from SQL.

Total       Status
--------    ---------
6           Cancelled
3           Disputed
6           In Process
4           On Hold
4           Resolved
303         Shipped

You need to add Cancelled, Disputed and Resolved together and then divide the result with the total shipped. All of this should be done with an Expression. So x/303 where x is the sum of the desired values.

It’s not difficult to implement the requirement in Birt. You should use computed columns in your data set.

Add aSUMon the columnTotaland a filter only matching the rows based on the columnStatusyou want to select. The expression should look like:

if (row["Status"] == "Cancelled" || row["Status"] == "Disputed" 
 || row["Status"] == "Resolved")

Computed Columns

create a second computed column only containing the “Total” value where the Status is Shipped.

if (row["Status"] == "Shipped")

Then create a third computed column where you divide both computed values and you are done.

row["sum"] / row["shipped"] 

shipped computed column

Comparison of esProc implementation:

1 =$select Total,Status from totalShipped
2 =A1.select(Status=="Shipped").sum(Total)
3 =A1.select(Status=="Cancelled"||Status=="Disputed"||Status=="Resolved").sum(Total)
4 =round(A3/A2,4)

The script will be clear at a glance. Especially when the data and calculation logic are more complicated, the advantages of using a simple script are more obvious, making report development and maintenance more efficient. For detail esProc integration with BIRT, see How to Call an SPL Script in BIRT.