reset variable for each group (crystal reports) - 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.

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.

Check last record of each group

My formula needs to detect when it reaches the last record in a group before the group changes. I tried using both OnLastRecord and creating a running total field (which resets on change of group) to do this. In both cases it only checks the very last record on the very last page of the report.
My ultimate goal is that I want my report to check if a number field, {#Calc} on the last record is < 0. If so output "Outsanding:" &{#Calc}*-1.
I have figured out my problem. I am now using:
{grouped field} <> next({grouped field})
which gives the value of last record for each group value.
Have you considered using the Group Footer for the group in question?
When you reach that particular footer, the active record will be the last one in the group. So any calculations you perform, or any fields you choose to print, will be based on the final record read in that group.
Note: If you're suppressing some records in the group, this might not work. In which case, you can instead use Shared Variables to store the latest valid value for Calc.
Then by the time you reach the footer, you can check to see if the variable is less than zero and display your Outstanding field based on the result.

Heading repeated for every record in the table

My report handles several Members based on a 4-column Members table.
For some reason, each Member is being repeated on the report for every record in the table. How can I configure this such that every member has a separate set of records?
In other words, repeating should consider "MeberName + Test" as one single unit.
Add a Group section based on your Member field. Then right click on that Group and select Section Expert. Check the New Page Before option to configure the behavior you asked for.
Additional help:
Insert page breaks between report groups with two-sided printing

Print field from first record in a group in the group footer

I have a series of transactions that contain a receive and return date and are grouped. In the group footer, I want to print the receive date of the first record in the group and the return date of the last record in the group. I created a formula to populate only when it is the first record in the group. But if the group contains more than one record, the formula field prints out blank. If there is only one record in the group, it prints OK. I'm using SAP Business Object Crystal Reports 2013.
There are a few ways to handle this. If you were sorting by Date, (which I've just learned you aren't) you could use a Summary to find the Minimum value. You'd place it in the relevant Group Footer and it should reset each time.
But since you're not sorting them by Date, I'd try setting up a Running Total that counts the number of records in the current Group (and resets on change of group.) Then set up a Shared Variable in a Formula that gets set every time the Group Count resets to 1. Finally, put another Formula in the Group Footer which prints out the Shared Variable.
Done correctly each Group Footer will display the first date value in that Group.

Resetting $V{REPORT_COUNT} for each group in 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