Jump to content
We've recently updated our Privacy Statement, available here ×

[solved] How to calculate sum by row and max in total for crosstab?


sanbez

Recommended Posts

How to display row with max summary value in last row? I am using IncrementerFactory implements JRExtendedIncrementerFactory.
But I am can't understand how "to say" jasper calculate sum in row (it's realized) and max (with Date of max - it's problem for me) for same measure of crosstab.
Any "date" (first column) is java-object with private field java.util.Date and java.lang.Boolean (it "marks" records for calculating maximum).

Full report:

converted-file.png.c75c7e29d82180be103ba725056fcfcf.png

In last(sum) total row I want to see row with data (instead of row "Max(date, values), etc..."):

converted-file.png.26a09d13245f88098630b17bda40abbd.png

Any advice greatly appreciated!

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

I am use java (ORM) for DataSource (new JRBeanCollectionDataSource(Collection)).  I don't use query. And using additional query requred additional time for calculating report. It's not effective.

Now I am think that better way is calculating max in java. I will add additional record into DataSource collection with total max. But in this case many data (sum for row? total sum) must be calculated "by hand". And I must add private field in "Date-object" for sorting (to display summary in last row.). It's not effective too :(
And formatting summary in row, total summary is more difficult. And power of JR is not using. Only display "pre-calculated" objects... :(  

Now I'm in a sad meditations :(

Link to comment
Share on other sites

Problem solved by same steps:
1. Set "None" to display row-summary and column summary
2. Calculate summary for row in java (calculate DataSource collection)
3. Calculate date of max and add row with max to collection (in java). In this row set dateMax = realDateMax+10000 years (It's for display in last row in report)
4. Date expression in jrxml: $V{peakDate}.getDate().getTime()>4000000000000L ? my.package.name.addYear($V{peakDate}.getDate(),-10000) : $V{peakDate}.getDate()     (Display correct data in last row)

It will be work only before 2096 year. It's enough for me :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...