Crystal Reports: select top N in subreport? - crystal-reports-8.5

I have to create a report based on a table storing broadcast email mailings history. Every time a mailing is sent, a row is entered into the Mailings table for each recipient - Mailings.ID, Mailings.CODE, Mailings.DATE, and Mailings.DELIVERED. Mailings can either be delivered or undelivered (T/F).
I need the report to show me those IDs whose previous five mailings (based on Mailings.DATE) were all undelivered (Mailings.DELIVERED = 0).
Having trouble figuring out how exactly to group/sort. Figure I have to group by Mailings.ID to start with - then sort within each group by Mailings.DATE descending. Then some sort of conditional formatting to display/suppress the group based on values of top 5 Mailings.DELIVERED?

first of all you should do a group by date, then a group by ID, then you will have to create the below formula in your ID group header to initialize your counter variable
WhilePrintingRecords;
Global numberVar record;
record:=0;
then place in your details this other formula
WhilePrintingRecords;
global numbervar record;
record:=(record+1);
record;
this formula will help you counting details record in order to suppress your details.
then in your details section expert you will put the following
Mailings.DELIVERED <> 0 or record > 5(this will suppress your detail section when the mailing was delivered or when you have more than 5 records )

Related

How to count number of grouped rows in the Crystal Report

I need to count and show number of rows of grouped data in the report. I already have number of rows of total data in Report Footer section (I used Count() function and that works fine), but I need to have total rows in the Group Footer section which shows number of rows of grouped data. The visible explanation of the problem is shown under.
Thanks.
----------------------------------------------------
Group 1
row 1---------------------------
row 2---------------------------
.
.
.
row N---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Group 2
row 1---------------------------
row 2---------------------------
.
.
.
row M---------------------------
--- I need here number of rows!---------------------
----------------------------------------------------
Total Rows: M+N
Try the solution
Create a formula #reset. Place the formula in groupheader and supress
Shared Numbervar count;
count:=0
Now create one more formula # Increment and place in section where there are rows I have assumed it as detail section and supress.
Shared Numbervar count;
count:=count+1;
count;
Now create one more formula #Display. Place this formula in Group footer
Shared Numbervar count;
Shared Numbervar Count_Final;
Count_Final:=Count_Final+count;
count;
Now create one more formula #DisplayFinal and place in Report Footer
Shared Numbervar Count_Final;
Count_Final
This solution may help someone,
Create a Running Total:
Choose a field
Select distinct count as Type of summary
Choose your group name in Reset section
Now drag and drop the running total field in group footer.
Refer the image below
This solved my problem
Create new formula field
{IM_INV.QTY_ON_HND}-{IM_INV.QTY_ON_HND}+1
{Existing field} minus {exiting field} plus 1
This gave me a "1" next to each detail line in a field I called {NumberForCount}
Because it was made this way it showed up in running total field options
Then made a running total field like normal in the footer
Another way to try by using Summary
Right Click > Insert > Summary
Choose Field (I choose string
value)
Choose "Count" to Calculate This Summary Combo box
Choose Summary Location in Where would you like to show this total
Then OK

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}

Increment a number for select group header sections per group

I have a unique question that I am not sure is even possible.
I have a report that has several Group Headers per group. What I would like to do is have select Group Headers (GH1a, GH1p, GH1w...) have an auto incremented number, which I will then turn into an roman numeral using roman(#function). The numbering would be independent on the number of actual groups, only Group Headers. There could be one to 100,000 records (groups) returned to the report but for each record(group) the Group Headers within each group would have select Group Headers numbered the same
EX:
GROUP A
GH1a: I
GH1b:
GH1c: II
GH1d: III
GH1e:
GH1f:
GH1g: IV
GROUP B
GH1a: I
GH1b:
GH1c: II
GH1d: III
GH1e:
GH1f:
GH1g: IV
etc....
Any help would be appreciated. I have tried to use a global variable x in both the report header and each GH that I want incremented using the following code:
in reportheader and/or GH1a //#iCountreset
Global NumberVar iCount:=1;
in each GH that I want incremented //#iCounted
Global Numbervar iCount;
iCount:= iCount+1;
then a second one to romanize it //#RomanCount
roman(#iCounted);
I currently have them hard coded but am trying to combine several rpt files into one where the only difference would be some GH sections would be suppressed and therefore not counted in the numbering.
Thank you in advance.
//{#reset}
WhilePrintingRecords;
Global Numbervar G1:=1;
//{#increment}
WhilePrintingRecords;
Global Numbervar G1:=G1+1;
//{#roman}
Roman({#increment})
** edit **
Ryan's comment was correct. My new approach uses subreports to increment a shared variable, which works.
Steps:
add {#reset} GH1a of 'main' report; suppress
//{#reset}
WhilePrintingRecords;
Shared Numbervar G1:=0;
create a subreport; place it in GH1b; add these formulae to it:
add to Details section; suppress:
//{#increment}
WhilePrintingRecords;
Shared Numbervar G1:=G1+1;
add to Details section:
//{#roman}
Roman({#increment})
You will need to add this subreport to each section that requires a Roman-numeral calculation. To make this process a little less painful, export the subreport ('save subreport as'), then reinsert it.

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.

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

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!