How can I filter a report with duplicate fields in related records? - crystal-reports

I have a report where I need to filter out records where there is a duplicate contract number within the same station but a different date. It is not considered a duplicate value becuase of the different date. I then need to summarize the costs and count the contracts but even if i suppress the "duplicate fields" it will summarize the value. I want to select the record with the most current date.
Station Trans-DT Cost Contract-No
8 5/11/2010 10 5008
8 5/12/2010 15 5008
9 5/11/2010 12 5012
9 5/15/2010 50 5012

Create a group on Contract-No.
Create a formula field to display most recent Trans-DT.
Something like: Maximum ({Trans-DT}, {Command.Contract-No})
Create your summary fields or running totals based on the newly created Contract-No group.
Edit:
To summarize costs and count contracts, you'll need a bit of trickery.
Add this (in a formula field) to the report header section:
// start the sum
// put in report header
WhilePrintingRecords;
Global NumberVar TotalCost := 0;
This goes in the report footer:
// final count
// put in report footer
WhilePrintingRecords;
Global NumberVar TotalCost;
TotalCost;
And place this in a formula field within your Contract-No or Station group:
WhilePrintingRecords;
Global NumberVar TotalCost;
if {Command.Trans-DT} = maximum({Command.Trans-DT}, {Command.Contract-No}) then
TotalCost := TotalCost + {Command.Cost}
else
TotalCost;
I'll leave the counting part to you. Good luck!

Related

crystal reports sum only last item in detail

I wish to display in the group footer the sum of the sold qty column (which is easily done) and then only the last value of the on hand qty column.
I think a variable can do this, but not sure how to do it as I'm new to Crystal and its variables.
Here is an example
Sold qty On Hand Qty
details 1 5
2 3
============================================
GF Total 3 3
============================================
details 6 10
3 7
============================================
GF Total 9 7
Put the field {yourTable.OnHandQty} in the group-footer.
This will show the last detail value and will work as long as there's no suppression on details.
Note: The "last record" is determined by the sort within the group. This means that if the sorting is changed, the wrong value will be displayed.
Yes !! You can do this using variables.
Step 1: Create a Formula Field Named as OnHand
OnHand
shared numbervar OnHand;
Onhand := (Your Table Field) + Onhand +;
Place this one in Details section and suppress it (Right Click
Formula --> Format Field --> Common --> Supress)
Step 2 : Create one more formula to display the result
PrintOnHand
shared numbervar OnHand;
OnHand;
Place this formula in Group Footer
Step 3 : Create one more formula Clear
Clear
shared numbervar OnHand;
OnHand :=0;
Place this formula in group Header and suppress it. (This is to clear the Onhand
Value for every records or group).

Crystal Reports - add results of grouping together

Really low level question, but it's been 5 years since I used Crystal Reports and I want to ensure that before I think about using it again that it would be suitable - I think it will.
I have two groups of data - Group 1 is Income, Group 2 is Expenses. I am looking to create a Profit result by a formula to take the sum of Group 2 away from the sum of Group 1. If I recall this is quite straightforward, but just throwing this one out there to begin with.
Thanks
are income and expenses 2 different values of the same field in the database? If so, create a formula like below to storage Income and expenses total values and place it on your group footer
if {database your field} = "Income" then numbervar Income := {your group total} else numbervar Expenses := {your group total}
Then subtract them in a second formula placed on your report footer(numbervar Income - numbervar Expenses)

How to summarize a formula field in crystal reports?

How do I add a running total or summary field on a formula field in crystal reports?
// Sample Report
Serial No. Premium Commission Net (Premium-Commission)
-----------------------------------------------------------------------------
1. 10 4 6
2. 40 30 10
---------------------------------------------------------------------------
Grand Total 50 34 16
In sample report, Net (Premium-Commission) is a formula field which gets evaluated for each row? How do I add a grand total/summary field for my formula? It seems we can add a summary field to only Command fields.
Suppose Net (Premium-Commission) formula field name is {#Net}. Now you have to create another three formula fields.
Initializer: this formula filed will be placed in header section to reset all variables.
Increment: this formula field will be placed in detail section to summarize the value.
Total: this formula field will be placed in footer section to show total of {#Net}.
Code will be writen in formula fields as below.
{#Initializer}
WhilePrintingRecords;
Numbervar dSum :=0;
{#Increment}
WhilePrintingRecords;
Numbervar dSum; //Don't initialize zero
dSum:=dSum+{#Net}; //{#Net} formula field must be return numeric value
{#Total}
WhilePrintingRecords;
Numbervar dSum; //Don't initialize zero
dSum;
Place all formula fields in their appropriate section and suppress {#Initializer} and {#Increment} formula field.
If you are using any calculation then that is not possible but one workaround would be to sum the each row and reset it in header.
Create a formula #Intialize in that write below code:
Shared NumberVar count;
count:=0
In detail write below formula and place it after Net (Premium-Commission).
Shared NumberVar count;
Count:=count+<>
\
3. Now create one more formula #Display and place it in footer.
Shared NumberVar count;
count;

How to avoid including duplicate records in group summaries in Crystal Reports

I have a report which groups the record by company, customer, Invoice, date... but i have duplicated records. I want to sum the total and not include the duplicate records. I use the running total, and ongroup change to invoice. It works for the grand total in the report footer but i still want to get a subtotal in this case will be 15006.26 + 39772.26 + 21140.00 + 4571.92.
I tried to use the whileprintingrecords and declare a currencyvar=0 and recalculate the total like this
Whileprintingrecords;
currencyvar Amt;
if previous ({brptARAgeUPSSequence;1.Invoice})<>{brptARAgeUPSSequence;1.Invoice} then
currencyvar Amt:= Amt + {brptARAgeUPSSequence;1.AgeAmount}
else if onfirstRecord then
currencyvar Amt:= {brptARAgeUPSSequence;1.AgeAmount}
But I get all the O , i do not know what is the problem
You need two Running Totals: one for the grand total and one for the group level. Since it sounds like you've got the one for grand totals working, all you need to do is duplicate that one and make one small change to it to get it to work at the group level.
In the new Running Total settings, just change the "Reset" field from "None" to "On change of group" and select the group level you want this to work at. Then, place this new RT in the appropriate Group Footer section of your report.
Seems like Amt is being re-declared. Try this
Whileprintingrecords;
currencyvar Amt;
if previous ({brptARAgeUPSSequence;1.Invoice})<>{brptARAgeUPSSequence;1.Invoice} then
Amt:= Amt + {brptARAgeUPSSequence;1.AgeAmount}
else if onfirstRecord then
Amt:= {brptARAgeUPSSequence;1.AgeAmount}

How do I create a Grand Total Summary based on a Group Summarized Formula In Crystal 10?

I have the following formula: #Sales_Cost
(Sum({Estimate_Retail_Inventory_Change___Detail.Sales_Ret_Final_Amount}, {Estimate_Retail_Inventory_Change___Detail.Inv ID}) -
(Sum ({Estimate_Retail_Inventory_Change___Detail.Sales_Ret_Final_Amount}, {Estimate_Retail_Inventory_Change___Detail.Inv ID}) *
{#GM%_For_Cost_Sales}))
This produces the following results and I have placed in my GH2 section:
592.77
1038.26
2628.38
3598.62
356.58
I want to total those values for my Report Footer, but I get the error message, "This field cannot be summarized".
How do I do this?
You need to create a manual running total. To do this you will create 3 new formula fields.
The first one goes in the report header to initialize the running total variable.
WhilePrintingRecords;
NumberVar manualTotal :=0;
The second one goes in the group header with your summary formula.
WhilePrintingRecords;
NumberVar manualTotal := manualTotal + {#Sales_Cost};
The third one goes in your report footer to display the calculated value.
WhilePrintingRecords;
NumberVar manualTotal;
manualTotal;;
Assuming {#GM%_For_Cost_Sales} will not vary within each Inv Id value (though it could vary across different values) and that the group for GH2 is on Inv Id, the simplest way to do this would be to change your formula item to:
{Estimate_Retail_Inventory_Change___Detail.Sales_Ret_Final_Amount} *
(1 - {#GM%_For_Cost_Sales})
- and place summed #Sales_Cost fields into both your GH2 group header and report footer sections.