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.
Related
First, I am using Crystal Reports 2011. I need to suppress records in a group that fall between the first two records and the last record. In other words I only want to see record number 1 and 2 and the last record. I can easily suppress records that are not the first two, but getting the last record to not be suppressed has me at a standstill. I am creating a report where we want to only show the first, last and next-to-last time we purchased items. Some items have been purchased many, many times. I have the report grouped by part number, then all the dates we purchased the part (and other data) are in the group details. I have tried using a running total count, where I simply suppress details that are not 1 or 2, but the last record count varies depending on how many times we have purchased the item, so I don't know what the last count number will be for each group to use it in the suppress formula. I have also tried with declaring a variable and increment the variable for each record, but end up with the same problem as using running total count. Anyone have a suggestion?
To clarify my question a little further, I am sorting the group by date, most recent date first. So record count 1 is the last time we purchased and record count 2 is the next-to-last time we purchased. So by using record count I can suppress records that are not 1 or 2. The problem comes when trying to figure out how to not suppress the last record (which is the first time we purchased). Below is a link to a pic of what my report looks like with nothing suppressed. For this part I would want to suppress all records except 1, 2 and 5. But again, the last count number will change per part number depending on how may times we have purchased the part.
Help is greatly appreciated!!!!
Report cropped image
Using Crystal syntax you can test on OnLastRecord which returns true if you are on the last record or false if not. Simply suppress accordingly.
EDIT:
As pointed out by jmears, the above won't work for multiple groups of differing products.
Instead you can add a running total field to count each record within the group, reset on change of group. Then suppress the details based on the running total not being 1 or 2 (for the first two records) and not equal to the total count of records for the group.
Here's an example suppression formula, where {#rt} is the running total count of records. It uses the Count function to return the total count for the group
not({#rt} = 1 or {#rt} = 2 or {#rt} = Count ({fieldToCount}, {GroupField}))
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.
What I would like to do is either suppress a group or (if possible) write this in to a selection record.
The goal would be to display all records in the group if any one of the records in the group meet the requirements.
For example if my group has three records and my requirement is that one of the records have a specific value in one field. Then display all three records in that group. Otherwise, if none of the three have that value then suppress the group.
I know where I need to put the formula and I thought the following would work but instead it only gave me the records that met the requirement not the others that accompany it.
Placed in the suppress group formula field:
if {table.field} <> "1" then true else false
Any thoughts on this?
Looks like I got it figured out. Here's what I did:
Create a Formula Field to check if the value exists in the record as follows:
if {table.field} = "X" then 1
Create a Summary Field of the formula field just created and sum the total for the formula field effectively counting how many records in that group have the value sought after.
Go to Section Expert for the desired group and Suppress using the following formula.
if Sum ({#Formula}, {table.field_2}) < 1 then true
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.
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.