Crystal Reports - Get First, Second and Third occurrence of linkedTable value - crystal-reports

I have the following One-To-Many scenario:
One Record -> To -> Many Notes (of types X, Y and Z)
In the page for each Record, I need to include only the first 3 Notes of Type X in chronological order.
How do I do this? I've tried setting 3 subreports, but I can't tell the second and third subreport which notes have already been selected as part of the prior occurrences.

Just an extension to your solution.
First select only select 3 records to be retrieved from database.
Now sort either ascending or descending order in all 3 sub reports.
Now in sub report 1 suppress 2 and 3 records in the same way in second sub report suppress 1 and 3 records and in sub report 3 suppress 1 and 2 records.
You can suppress the records by placing the special field Record Number and suppress condition would be
if recordnumber = 1
then true
else false
Same way for second and third records.

{#ResetCounter} // Place this in the group/page header where you want to restart the counter
global numbervar counter := 0;
Place this in the section suppression formula
global numbervar counter;
counter := counter + 1;
counter > 3; // if true then suppress
If you have multiple sections to suppress make sure you only increment one time. So just remove the middle line in the subsequent suppression formulas.

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).

Is it possible to suppress a group header based on various conditions in details?

I have report with a group 1 and group 2. For formatting purposes group 2 header and details are suppress and all information is presented in the group 2 footer. I have set up the report to suppress the group 2 footer if a certain condition is met, The means that sometimes the entire section under the group 1 header is blank and I want to suppress it.
Here is how it is set up
Group 1 - Employee
Group 2 - Client (suppressed)
Details (suppressed)
Client name field1 field 2 field 3 field 4
For fields 1-4 the are possible returns of "Draft", "Final" and null. I'm only looking for "Draft" and null values.
So how I've set up the group 2 footer is to just return the client name and a formula summing up the values of all four fields {#draft}
if {#divDraft} + {#convoDraft} + {#yearDraft} + {#rovDraft} >= 1 then "Draft"
else if {#divFinal} + {#convoFinal} + {#yearFinal} + {#rovFinal} >= 1 then "Final"
else " "
I then suppress the footer based upon {#draft} returning "final"
Is possible to suppress the group 1 header if every client in that group has either all four fields returned as null or at least one returned as draft?
I tried running a subreport and then placing that and a shared variable in the group 1 header but that didn't work right
WhilePrintingRecords;
Shared NumberVar totalSuppress;
Global NumberVar suppression;
suppression := Shared NumberVar totalSuppress;
The {#totalSuppress} formula in the shared report added the times at least one "draft" was returned with the number of times all four fields were null. I placed that in the footer of the subreport and then {#suppression} in the main report group header.
What I got was a pattern where the first group header was returned 0.00 where it had 4 results and 4.00 in the group footer. Then the next group had 4.00 in the group header where it had 1 result and 1.00 in the group footer. And the next one had 1.00 in the group header and so on.
I tried to do a formula to reset the variable with each group header. So I wrote
Global NumberVar suppression;
suppression := 0
But all that did was return 0.00's in the group header.
Any other ideas would be welcome.
RE: Tried new formula
if {sales_div.draft_pend_approv_Value} = "Draft" or {sales_div.draft_pend_approv_Value} = "Pending Approval"
or {convoSales_200.pending_approval_Value} = "Draft" or {rov_client.pend_draft_Value} = "Draft"
or {yearly_sales.draft_pend_Value} = "Draft") then 1
else if isnull({sales_div.draft_pend_approv_Value}) and
isnull({convoSales_200.pending_approval_Value}) and isnull({rov_client.pend_draft_Value})
and isnull({yearly_sales.draft_pend_Value})
then 1
else 0
If I understand correctly, you're trying to use the result of a Running Total Field to suppress a header - which won't work as the running total is only calculated in the footer.
You can try a different approach. Make a Formula Field which will go into your Details section. It should simply check if that row is the kind that you want to show, something like:
if (isnull({field1}) or isnull({field2}) or ... or {field1} = 'Draft' or {field2} = 'Draft' ...)
then 1 else 0
Then in the Group Header #1, in Section Expert, inside the Suppress formula put
sum({#check},{Employee})=0
where {#check} is that formula field and {Employee} is the field on which Group 1 is created

Displaying only the last of a sequence in Crystal Reports

I have a report that will occasionally have more than one detail record in a group. In such a case I only want to display the last in the sequence. I have a sequence number associated with each record so I need to suppress all detail rows in the group other than the one with the maximum sequence number.
I've tried using a global variable to recalculate the max value as of each detail record but I haven't been able to write a formula that, while printing, can use this maximum sequence number to suppress the row if it does not contain a value equal to the max sequence number.
From what i understand you have data organized by this:
Data1 Data2 SeQuencenumber
1 a 1
2 b 1
2 c 2
2 d 3
And from what i understand your want your output look like (group by Data1):
Data1 Data2 SeQuencenumber
1 a 1
2 d 3
To do so you need to write formula in detail section which compares your current detail sequence number and count of all for that group (Data1). Right-click your detail section and write formula here
Formula looks like :
if {SequenceNumber} = count ({SequenceNumber},{Data1}) then true
else false
Hope it helps, if you have any further questions feel free to ask.
try like this:
Shared Stringvar array concatenate;
concatenate:=concatenate+CStr(Sequencenumber);
now in suppress condition of details:
Shared Stringvar array concatenate;
if Maximum(concatenate)=Sequencenumber
Then false
else true
I had tried a solution similar to the one from KuKeC but with the maximum function instead of count. But while reviewing the KuKeC solution I finally saw that I was already suppressing the detail band when a date in the detail did not match a parameter date, yet the maximum function was giving the max of all data whether displayed or not.
So I first needed to add a formula field that would return the sequence number only if the data date matched the parameter date
if {PSLRegister.PSLRPPStartDate} = {?PP_Start_Date} then
{PSLRegister.PSLRSeqNo}
else
0
then I used this formula field in the equation to suppress the detail record
Maximum({#SeqIfDateMatch}, {TrnsltEmployee.TSEmployeeID}) <> {PSLRegister.PSLRSeqNo}
Thanks to all

Print Multiple Copies of Record Crystal Reports

I have a report that is only one record, however, the user specifies how many times it needs printed, let's say 10. Each time it prints it prints 4 of the same report. Like this, Page 1 x 4, Page 2 x 4, Page 3 x 4, etc. With 10 copes their will be 40 pages altogether.
Update:
I was able to get all the pages I needed based on the values the user inputs. So if there are 10 pallets I have 40 pages of labels, which is correct. Now the control number part that needs to be displayed. It is kind of like a page number but every 4 pages the number needs to increment by 1. I assume I can use WhilePrinterRecords and some how increment, but I am still new to Crystal and unfamiliar with it.
Example:
Page 1: Control number 1
Page 2: Control number 1
Page 3: Control number 1
Page 4: Control number 1
Page 5: Control number 2
Page 6: Control number 2
Page 7: Control number 2
Page 8: Control number 2
This would continue until there is no more pages to print.
if you want 4 copies for each label, what you could do is create 4 sections on the report with the same info. Make sure that you assign the label size to each page(e.g. 4x6). e.g. if you have that info on your header, create PHa, PHb, PHc and PHd, same for details or PF.
don't know if this could work for you, but at least is a recommendation. You can create suppressed sections with the same info(e.g. 10 sections) and create a parameter that control that suppress condition defaulted in 4. If the user what to print 5, it will enable section 5th, same if want to print 3 it will suppress the 4th.
Upadte: how to get the increment:
place a formula on your page footer like below one. It will return value when gets an integer and suppress it when is equal to 0(right click on it, number tab, customize, suppress if 0).
if pagenumber = Ceiling(pageNumber,4) then numbervar page := page +1
then place another formula on your PF as well like below one and suppress it when pagenumber = Ceiling(pageNumber,4) so it won't show when the other has value and put one overlapping the other to get the value in the same place.
if {1st formula} <> 0 then numbervar page1 := {1st formula};
page1 + 1
2nd Update:
Because is a label and your details are acting as a new page do this:
create a new detail section, so you will have details a and b and place your formulas on details b
I have used additional tables for such tricks; these tables must be linked to report to multiply main query results. Some care has to be taken to not allow multiple users printouts to mix.
Example, assuming your report query has some unique id to link and your user/session has also some unique id:
you create table cr_special(reportid int, userid int, ctlnumber int)
you design report, linked to this table by reportid and filtered by userid; changing ctlnumber field is taken from your special table
before printing, you delete all records with reportid/userid combo and insert new ones
you print report, giving userid as parameter
Say you want to print 10 reports with increasing numbers - then you insert 10 records into your special table with ctlnumber increasing from 1 to 10.
Variation of this solution is to use some other non-related table, like our all-dates-containing dates table :)
Both of these solutions are ugly, but they usually work.
Another approach is to use some stored procedure to return these sequential numbers as records and link your report to such procedure; Crystal Reports and stored procedures do not behave always well however.

Require multiple pages for a single bar chart in Crystal Reports 2008

I am creating a bar chart where the values are the maximum of an AVE_ZSCORE field, and this is set as "on change of" a PARTICIPANT_CODE field. On any given occasion, I could have up to 250 records in this chart and therefore I need to split the chart over a number of pages. This number of records is dynamic however, and can range between 150 and 250 records.
I have tried the solution in this thread http://www.tek-tips.com/viewthread.cfm?qid=1257385 and I've followed the instruction as best as I understood (please bear in mind that I'm quite new to Crystal Reports). I created a formula, inserted it in the details section which I then suppressed, then inserted a group on that formula, and inserted the chart in the group footer section. The formula I'm currently using (which I called "chart") to test this out on 4 records is:
WhileReadingRecords;
numbervar cnt := cnt + 1;
if cnt in 1 to 2 then 1 else
if cnt in 3 to 4 then 2
My problem is that the output of this results in 3 graphs of the following instead of 2 graphs containing 2 records each:
a group output of 0.00 which has all 4 records (B2, BB, KK, MM) in
one graph
a group output of 1.00 which has only one of the records (BB)
a group output of 2.00 which also has only one record, which is the
same record of the previous graph (BB)
If I change the formula to display as follows:
WhileReadingRecords;
numbervar cnt := cnt + 1;
if cnt in 1 to 4 then 1
Then the output becomes
a group output of 0.00 which has all 4 records in one graph (B2, BB,
KK, MM)
a group output of 1.00 which has one record (BB)
So firstly, I don't understand the formula that I'm using or how it works, and secondly I have no idea how to get this working so that I can easily specify the number of columns per chart
Unfortunately it's hard to say something without total understanding of your report layout. Some screenshot will easy things alot. As nothing yet specified I expect you have only one (mentioned) group in your report.
To achieve you goal you should render your chart as many times as different group values will be. This is how details section of group is rendered. Not footer or header. As chart can't be added to details section additional dummy group should be created. So in result there will be 2 groups:
Outer group (#1) will be based on your formula field and have no header/footer
Inner group (#2) will be used to show chart in either header or footer
Group #2 can be based on same formula as group #1 (or any other formula/field, it shouldn't matter).
Btw, instead of calculating count manually, like in your code
WhileReadingRecords; numbervar cnt := cnt + 1;
You can use Running total fields, with type of summary count on any field you want to control. Such fields are very customizable, so you'd like them.