Variable Calculations


I have a few column of integers taken from a database. In a subreport, I want to have a summary table of sorts with things such as average.

I created a variable to calculate the average with the built in variable calculations, but this is calculating the average line by line.

This was easily fixed by setting the evaluation time to report. It now calculates the total average but is printing it out for each line and I just want it printed once.

I attempted to solve this by using a print when expression and this works to print the value once, but the subreport still generates blank pages for each line after the first print (the subreport is one row in size). So in a column with 15 integers, the average is calculated and printed, but there are 14 blank pages after it.

How can I have things such as sum, average, lowest, highest, standard deviation, etc. calculate and print one number?

Moving the value in the subreport to the summary band allows it to be shown once. But when this subreport is imported into the master report, it still repeats for each line in the detail band. I want the subreport in the detail band beside the data chart, see below.

matt.mitchell's picture
Joined: Jan 17 2013 - 7:22am
Last seen: 6 years 8 months ago
Matt - are you displaying the results of these calculations in your detail band? Try moving them to your Summary band.
lisacbeaton - 6 years 9 months ago
I moved the variable in the subreport jrxml to the summary band. Previewing that gives me one value. Problem with this is that in the master report it still repeats the subreport. I've mocked up what is happening in here:
matt.mitchell - 6 years 9 months ago
Unfortunately, anything placed in your detail band will be repeated with every detail band output row, unless you use a "Print When" expression to limit the output to a certain row number. What if the left-side portion was actually a subreport, and you dropped that into an outer wrapper report. In the outer report, you could split the detail band into 2 columns and display the subreport with the data on the left. In that subreport, calculate your averages in the report footer but don't display them. Pass them back to the outer report as return values. You would be doing all of this with the goal of having only one row in the outer wrapper report's detail band. Maybe someone else will have a better solution. I have had to get creative sometimes to achieve the layouts I'm looking for. For example, if you know you're always going to have X number of rows in your data table (I do a lot of "this month, last month, and the month before that" in my reports), you could use something like Oracle's decode function (not sure what kind of database you're using) to get all of the data in one row, and then you can arrange your text fields as you please within the single output row.
lisacbeaton - 6 years 9 months ago

1 Answer:


Option 1: Rather than using a new colum to show average for all columns, show average at bottom of each column by using summary. In below table i am doing some in summary section.

Total 98

Option 2: You can control your report layout via java code. I mean whatever object you passing to the report add two more variable. While you are iterating your collection from database populate these additional columns with your catlculated value for first 3 rows to show 3 different values.

anaullah's picture
Joined: Jan 22 2013 - 5:54am
Last seen: 6 years 2 months ago