I'm new to JasperReports, but I kind of feel like I'm getting it. After all it is just another mark-up language.
My scenario is that I have a table of data, with the date and some other text columns, and I want to to display a subtotal for each section of the data based on a date. I am expecting zero, one, or many dates to be in the table.
I have a variable defined that calculates the sum of the rows, but I want to reset the sum to zero with each sub-group, is it possible?
Here is my Variable declaration:
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[(($F{ROW_NUMBER}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
Is there a way I can use this variable, resetting to 0 when a new date is found, or am I using the wrong type to do what I want?
As a caveat, I am editing the .jrxml file in a text editor, not iReport.
What I was able to figure out from reading the dtd is that groups are available to trigger a reset event.
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum" resetType="Group" resetGroup="SubCalc">
<variableExpression><![CDATA[(($F{ROW_ORDINAL}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
<group name="SubCalc">
<groupExpression><![CDATA[$F{ROW_ORDINAL} == 1]]></groupExpression>
</group>
So when the ROW_ORDINAL == 1 it triggers a reset event, which sets the value of G_COUNT to the initialValueExpression
Related
Crystal reports uses PreviousValue (fld) What is the equivalent in Jasper reports?
I have searched online for possible answers but as yet not found anything. Any help would be appreciated.
There's no direct way to get the previous value of a field in JasperReports, but it can be done using two variables like this (the variable class should match the field type):
<variable name="PreviousFldValue" class="java.lang.String">
<variableExpression><![CDATA[$V{CurrentFldValue}]]></variableExpression>
</variable>
<variable name="CurrentFldValue" class="java.lang.String">
<variableExpression><![CDATA[$F{fld}]]></variableExpression>
</variable>
You would then use $V{PreviousFldValue} as the previous value of the field.
Note that the order in which the variables are declared is important, the solution relies on PreviousFldValue being calculated before CurrentFldValue.
I have a PDF report split in several pages.
In every page I may have one or more groups. What I need is a count of current group number inside that page resetting at page change.
So the first group in page has 1, the next one 2 etc...
When I change a Page, the count has to restart from one.
I have found this good variable definition but it counts current group number for the entire report, ignoring the page.
<variable name="currentGroupNumber" class="java.lang.Integer" incrementType="Group" incrementGroup="GroupName">
<variableExpression><![CDATA[($V{GroupName_COUNT} == 1) ? $V{currentGroupNumber}+1 : $V{currentGroupNumber}]]></variableExpression>
<initialValueExpression><![CDATA[1]]></initialValueExpression>
</variable>
Any ideas?
The variable is missing resetType="Page"
Also, the variable looks a little more complex than it should, something like the following might do:
<variable name="currentGroupNumber" class="java.lang.Integer" calculation="Count" incrementType="Group" incrementGroup="GroupName" resetType="Page">
<variableExpression><![CDATA["foo"]]></variableExpression>
</variable>
I have a report that needs to have an image printed only in the last row of the table of each page.
How can I create my print when expression?
Edit:
Sorry for my poor exemple.
until now, i created this variable
<variable name="rowsOnPage" class="java.lang.Integer">
<variableExpression><![CDATA[$V{rowsOnPage} + 1]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
and i try this print when expression:
$V{rowsOnPage} == $V{REPORT_COUNT}
But this expression print the image in each row of table.
As Petter says, providing an example of what you've tried and how close you've got so far would be helpful.
In the meantime my suggestion is that you add a max rowcount value to your SQL and return this as field in your JRXML as e.g. maxRowNum. With this you could then use a printWhen at the point when $V{REPORT_COUNT} == $F{maxRowNum}
This assumes you have access to the SQL part of your code and can play with this.
I have a report, with the fields A and B coming from my database. In the select statement sometime A and B are null.
Problem is when I ask for the group sum of A - B and one of the record has a null in it the total for the sum is null.
How do I get around this?
In jasper-reports variable expression you can use ternary operator
($F{value1}!=null?$F{value1}:0)
which means if value1 is different from null then use value1 otherwise use 0
jrxml variable declaration example
<variable name="varWithTernary" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[($F{value1}!=null?$F{value1}:0)-($F{value2}!=null?$F{value2}:0)]]></variableExpression>
</variable>
With these kind of statements your are able to handle null value as you like
I need TO add a column sum to column footer of table object for each page.
If I create variable and set sum aggregation function than sum value appear for full report. But I need sum column data for each page, not for full report.
Can anyone help me solve this problem?
This is not a solution for the jr:table component since it uses a subdataset where its not allowed to set resetType="Page", but using a subreport it can be used.
I don't think there is a work around in components (jr:table,jr:list) using a subdataset but would be happy If someone can prove me wrong
Solution using subreport
On your variable set resetType="Page"
es.
<variable name="var" class="java.lang.Double" resetType="Page" calculation="Sum"/>
....
</variable>
For more info on resetType see JRVariable API
On your textField set evaluationTime="Page"
es.
<textField evaluationTime="Page">
....
</textField>
For more info on evaluationTime see JRTextField API
In case of Dataset set resetType="Report"