I am working some time with Jasper Report Studio and I have a need that I cannot fulfill.
I am making Invoic Reports and it is necessary at the end of each page you write the total sum of all lines (Monetary Amount) and at the beginning of each page put the same value. Each new page you will have a total that is the sum of all lines since beggining of report.
Now, I using Detail Band for that and as far I can see the Jasper create all Detail Band (all pages) and only after it will split that on pages, meaning that the place where detail band is broken to be fit inside each page is calculated when detail band is all completed.
This mean that inside detail band I can not use any calculations to sum because Jasper does not now at that time where the detail band will be split (it will give the total some of all pages on each page or null) and outside I can not have any info about that because detail band was already made and is just a drawaing (I am generating PDF)
So, there any way of doing this, on each page put a calculations with info regarded only with that page?
I already work with variables, return that varaibles, using calculation at the end but nothing.
With my best regards
take a look in my answer to this topic. https://community.jaspersoft.com/questions/1139321/calculate-sum-table-column-page
There I described, what seems to be the problem when using variables for creating "Carry overs" from one page to the next page.
If you could set the detail band "splitting type" to "prevent" instead of "stretch" it will work. But if not, it becomes (unfortunately) a pain in JasperReports!
So my final (and working for sure) solution was, to "tag" each price/total field that should be used for later calculation and to sum up all page totals AFTERWARDS... so when the WHOLE report was finished and the JRPrint Object was returned but before send to printer/pdf-exporter.
You can then iterate through the pages, sum up your tagged fields per page and put the current carry-over sum to the textfield in columnfooter at current and columnheader at next page. That's much easier than to play around with the "tricky" band calculation and variables.
But of course it's just possible, when you use JasperApi for printing/export and not JasperSoftStudio or plain JasperServer functionality.
hth + regards
Hi, first many thanks for you reply. I was trying do find a way but still not working using variables and get them to the main report. I am using a list on Detail Band. On that I have the values but when I return on all pages I have Initial Value of the Expression and on last page I have the Sum of all values.
Also I was trying to get the page number to have a indexed sum but on detail band all pages have same number or are null. So, using this approach I can not have any value.
And a info, this could make some difference. I am using the XPATH Adapter to read information from a XML and populate the report. I am not using directly the JAVA API.
A question, where you put the total per page on your example? A second detail band? Here I can not add nothing more to may detail band and a second detail band is evaluated after the firs one finish. I using Jasper Studio Version 6.6.0. Your example is using a subreport on detail in stead of a list? That make difference?
With my best regards