Resetting $V{REPORT_COUNT} for each group in Jasper reports - jasper-reports

I am using $V{REPORT_COUNT} in JasperReports to print serial number and it works well. But when I grouped by a field and started each group on a new page the serial number still continues across the groups.
I need to reset this variable $V{REPORT_COUNT} for each group.
Thanks.

If you want a count that resets on each page, then that's not $V{REPORT_COUNT} by definition.
It sounds like you want the built-in variable $V{PAGE_COUNT}. Or you might want the built-in $V{MyGroup_COUNT}.
More generally you could create your own variable to count what you want. But the built-in ones probably meet your needs in this case.

when you create a new group in i report, a new variable will be automatically created in variables of ireport. Take that instead of report count. the sl no will start with 1 for each group.

the variable is created by the group name eg. if groupname is grp1 then variable created is grp1_count

Related

Crystal Reports: price for latest transaction

I need to create a field to put on group footer #1 that shows the latest price by customer type. The grouping is item_ID (see below). So for example if there were transactions over time with varying prices to Factories and to Retail stores, it would only show the price for the last time that item was sold for a factory(I have a separate field for retail stores). I have tried a few things but nothing is working. For example:
On the detail level:
if {TRANSACTIONS.TRANDATE} = Maximum ({#FactoryTranDate}, {TRANSACTION_LINES.ITEM_ID}) then
{TRANSACTIONS_LINES.PRICE}
FactoryTranDate is basically: if customer type = factory then trandate. Then I created a max of this on group footer #1.
This appears correctly on the transaction line but if the last transaction for that item wasn't to a factory, it will be 0 on the summary line. I tried to do a Max of that detail level field but it doesn't come up for my summary fields, I am assuming cause it gets confused upon doing a summary of a summary?
Sounds like the problem you are running into is the column of data you are trying to print in the footer has multiple rows and you can't predict where the value you want might be within those rows. So by the time you get to the footer, it only has the value held by the last row that printed.
To get around this you would want to use a few formula fields to create variables that can be used to store the value you want from the correct row when it is printed.
I would plan to use 3 formula fields. One to initialize your variable and set it to a default value of zero. Place this formula field in the header that corresponds to your footer and this will ensure the variable exists and is reset to a default value for each grouped value in this header. The formula will look something like this:
WhilePrintingRecords;
Shared NumberVar price:=0.00;
The second formula will declare the same variable again, and it will also include some logic to know when to set the value of the variable. This formula field should be placed within the section that prints the detail records for the grouping. The formula would look something like this:
WhilePrintingRecords;
If <condition to evaluate> Then
Shared NumberVar price:={TRANSACTIONS_LINES.PRICE}
I'm not entirely sure what condition you will want to evaluate here though based on the information you've provided, but I suspect it will be along the lines of if customer type = factory. However, it should be a condition that is only true when you want to capture the price of the detail record within the grouping. If you have multiple cases where it might be true, then you will want to sort them in such a way that the one you wish to capture is printed last within the group. Since you stated that it should be the last factory price, then I would sort by Transaction Date and the variable will change its value with each record that has a true condition and will only keep the price from the one with the latest Transaction Date.
The third formula field is simply for printing the value of your variable in the footer. This field will be placed in the footer section and will display the value of the variable on your report. The formula for this field will look something like this:
WhilePrintingRecords;
Shared NumberVar price;
The formula fields used in the header and details sections can be suppressed if you don't want them to print on your report, but I would recommend waiting until you have the final value printed in the footer verified before suppressing them. This will allow you to see how the value of your variable changes as the report is generated if you are not familiar already with using variable in this manner. You may also want to read up on the scope of variables in crystal reports if this is a new topic for you. My suggestions here all use the SHARED scope, but there are also LOCAL and GLOBAL scopes. GLOBAL might work better in your case, but I tend to favor SHARED in examples such as these because they have the most broad scope. LOCAL definitely will not work for you here though.

Pass Record Selection Data to Subreport

I have a main report that uses a formula in the Record Selection. The numbers are set by choosing the "is between" option in the Select Expert. I need these numbers to go through to the subreport, however, no matter what I do, I can't get both numbers through to the subreport, just the one. Is there any way I can pass both these numbers through to the subrport? Neither of them are based on parameters, we use a system here at work where the parameter is set at runtime.
Attached is a picture of the main reports' Select Expert - I need to get the 2 and 6 through to the subreport. Is this possible?
Thank you.
The answer in the link below seems to work, if you have a similar problem. To quote:
Create two formulas
MinValue as Minimum({vw_P_SDL_MTDSummaryList.PAYROLLDETAIL_ID})
and MaxValue as Maximum({vw_P_SDL_MTDSummaryList.PAYROLLDETAIL_ID})
and pass them to the subreport as a parameter without linking it to any of the > field in sub report.
http://scn.sap.com/message/16971134#16971134

How to display count in group header in crystal report

I have a crystal report in C# windows application.
Three groups are there in the report.
I need to display count for each group.
For Eg:
1. Group1.1
1. Group2.1
1. Group3.1
1.ItemDetails1
2.ItemDetails2
2. Group3.2
1.ItemDetails3
2.ItemDetails4
2. Group 2.2
1. Group3.3
1.ItemDetails5
2.ItemDetails6
2. Group3.4
1.ItemDetails7
2.ItemDetails8
2.Group1.2
like this?
I tried running total,
Field To Summarize as Group1 field,
Type as distinct count
Evaluate- for each record
Reset- On change of group
but its showing 1 everywhere.
Can anyone help?
Try Never Reset. When you reset using the field that you count, you will always get an answer of one.

reset variable for each group (crystal reports)

how to reset crystal reports variable value to 0 again for different group, or if I can make a variable that work only on one group but different value for another group? thanks
Create one shared variable for each group. At corresponding group header, reset the value of shared variable to zero. Below is what you can write in group header formula.
Shared numbervar num:=0;
I hope this helps.
http://wijayatony.wordpress.com/2012/11/26/crystal-report-add-record-number-that-resets-when-group-field-changes/
check this it will be helpful
As we know, field “record number” from “special fields” in Crystal Report starts from 1 and increase one by one for each record until last page of the report. However, when we need a record number field that resets from 1 whenever the group field changes, we need to manually create it.To create the record number field, here are the steps:
Create a new “Running Total Field”
Give a name for the field, for example : rtf_recordNumber
Choose a field to summarize.
Set the “Type of summary” to “count”
On “Evaluate”, choose “For each record”
On “Reset”, choose “On change of group”.
Choose the “key” group name field that will reset the record number.
Click OK
Add the field to the report.
this instructions are from above link
I agree with the above answer but only small correction instead of group footer place the reset formula in group header.

Jasper Reports - Print when group changes

I am trying to print the last record of the group but the expression print when group changes: True does not seem to work. It simply prints all the records of that group. (I've grouped the record based on username).
I was having trouble with the same issue. Here is the work around that I came up with:
JasperReports has some automatically generated variables that may help you achieve what you want. For every group you create there is a counter that keeps track of the number of items in your current group:
yourGroupName_COUNT
In your printWhenExpression simply add an expression like the following to only print the textfield when your group ruptures:
$V{yourGroupName_COUNT}==1
-Benjamin
I don't think that attribute is doing what you think it does. It's supposed to be used in conjunction with isPrintRepeatedValues="false" and works the following way:
"if the repeating value you have suppressed spans multiple groups, you can make it reappear at the beginning of a certain report group if you specify the name of that particular group in the printWhenGroupChanges attribute." Ultimate Guide pg. 116
I've never used the 'print when group changes' functionality, but trying it now on a new report, I see what you mean - it prints for every detail record even though the group is not changing.
Instead of using the 'print when group changes' flag, uncheck the 'print repeated values' flag, this will probably give you what you want.