How to concatenate the first and last value of field and hide a specific record in table group footer in IReport

ireportjasper-reportstabular

I have a table component which shows some records in a group of year like this

For example:

Year   Month    SumMonth //group header
2009   Jan      1000     //table details
       Feb      2000
       Mar      3000
2009   xxxx     6000     //group year footer
2010   Jan      1100     //table details
       Feb      1200
2010   xxxx     2300     //group year footer

The "xxxx" part in the above table is which i need to modify.

I want to display the format like this:

"Jan-Mar" (for 2010 is "Jan-Feb")

The question is how to get the value of first month and last month and concatenate them into a variable (or not need to?), so that I can put it into footer?

The other problem is that how can I hide the records in specific year?

For example the final modified display may like this:

Year   Month     SumMonth //group header
2009   Jan-Mar   6000     //group year footer
2010   Jan       1100     //table details
       Feb       1200
2010   Jan-Feb   2300     //group year footer

You can see the whole records in 2009 are hided in the above table.
Which options or what expression should I set?

Best Answer

Create a variable called FirstMonth. Its Expression is $F{month} and its Calculation is First. Create a variable called LastMonth. Its Expression is $F{month} and its Calculation is None. In your case both should reset for each year. Then in the year footer it is as simple as this:

$V{FirstMonth} + "-" + $V{LastMonth}

If you don't want to see details for Year 2009 then set a Print When Expression in the detail band like ${Year}.intValue() != 2009

Related Topic