Increment, display, and print a number of pages up to a Parameter maximum - crystal-reports

I am trying to set up a Crystal Report to generate pallet labels which include a "Pallet N of M" line on each page.
The order in the database only has one entry, which contains all of the other information for the label(s). My issue is that the number of pallets isn't known until print time, and each label needs the same order information as well as a pallet ID. What I am looking for is for the user to enter a parameter for the total number of pallets, then have Crystal generate the correct number of unique labels.
For example, if the order has 4 pallets then Crystal should generate 4 copies of the label, the only difference on each copy being the last line which should read 'Pallet 1 of 4', 'Pallet 2 of 4', 'Pallet 3 of 4', and 'Pallet 4 of 4' respectively.
The only solution I can think of would be to create a number of sections equal to the maximum number of pallets, all containing my real data as a sub-report, then suppress any which are greater than the entered parameter. I am trying to avoid this because we may have greater than 50 pallets on a given order, so that would be tedious to create and is just not a very clean solution.
-= EDIT =-
Big thanks to Aliqux for the solution. In the end I needed to change the syntax to be Oracle compatible and also include the LINKVALUE field in the report, but the answer was 99% there especially considering I had not mentioned that my datasource was Oracle. The Command syntax I ended up using (with my parameter called TotalPallets) was:
SELECT
-1 AS "LINKVALUE"
FROM table
WHERE rownum <= {?TotalPallets}

You will need to Add a command to your tables.
1) Under database Expert in the Database you used select Add Command.
2) Click create to Create a Parameter.
3) Create the requested values, you can leave the Default Value blank if you want, and change the Value Type to Number. (I will be calling my parameter Counter)
4) Put the following in the SQL query where table is the main table you are using
SELECT TOP {?Counter}
-1 AS LINKVALUE
FROM table
5) Click okay and enter a value if prompted
6) In links link a number field, that will never go into negative numbers as we are using -1 for a base, to the LINKVALUE in the Command Table.
7)Link Options are as followed
Join Type: Inner Join, Enforce Join: Not Enforced, Link Type: !=
8) In your report create a formula with a shared numbervalue the starts from one.
shared numbervar counters;
if counters = {?Counter} then counters := 0;
counters := counters + 1
9) You can use that formula and the Counter Parameter for your labels
totext({#Counts},0,"")+" of "+totext({?Counter},0,"")
Credit reference: https://blogs.sap.com/2014/01/24/duplicating-data-details-records-n-times-eg-repeating-labels-n-times/

Related

Crystal Reports print labels based on query count

I have a dataset and I need to loop through the records and print a crystal reports label based on how many pallets I'll have.
So in this instance I need the first record set to print 9 times the second to print 5 times, the next to print 4 then 12 for the last.
Option 1: At least one of the 3rd-party desktop Crystal reports schedulers (ses list [here][1]) provides an option to print copies governed by a Crystal formula.
Option 2: if you can create a "REPEATER" table with a single column (How_Many) containing a row for each value: 1, 2, 3, 4, 5, 6...
In your report, add the REPEATER table and add a join condition of
Pallets_Quantity >= Repeater.How_Many
If the ">=" join option is not available, remove the join to the REPEATER table and create this condition in the Record Selection formula:
{Pallets_Quantity} >= {Repeater.How_Many}
This would cause each order to be duplicated as many times as the value of {Order.quantity}.
Option 3: if the quantity is fairly small, you could create cloned sections as Detail b, Detail c, etc. and control which ones are suppressed based on the quantity.
[1]: https://%20at:%20https://kenhamady.com/productlinks/default.html#desktopsched)

SSRS Grouping Summary - with Max not working

This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.

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.

Crystal Reports and Adding values

I am using Crystal Reports XI and I'm trying to add a particular column if one column or another column is set to one.
Here is the current preview:
Username (GROUP 1)
MONTH (GROUP 2)
DATE SUBJECT TOTAL_TIME
End of group 2
End of group 1
Now I want to add the values in total_time if one of the two hidden fields contain 1 (true).
I tried using sum() function but it didn't work as it added all the times together.
I'm still new to Crystal Reports and I tried searching on google but nothing came up similar to what I need.
Any help would be greatly appreciated.
One alternative that I can suggest, You can use Parameter fields on your report.
Do the calculation on Code behind and set the calculated sum to parameter field on Page_Load event of Crystal Report page.
This parameter field will be used to display the sum on report page.
Please check this link to see
-How to create Parameter Fields:
http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crtsktutorialscrvparametersdiscretecreatingreport.htm
-How to set values in Parameter Fields:
http://msdn.microsoft.com/en-us/library/aa289936(v=vs.71).aspx
Your best option will be use "Running totals" by this way you can control the flow by keeping a condition to sum when the required column is 1.
Did you think about small trick? You wrote: I want to add the values in totaltime if one of the two hidden fields contain 1 (true).
Under these circumstances you can calculate helper field Total_Time_Conditional using formula:
Total_Time_Conditional = IIf(HiddenField1 = 1 or HiddenField2 = 1, 1, 0) * Total_Time.
This will multiply Total_Time
by 1, if any of hidden fields is 1
by 0, if both hidden fields are 0
Calculating Sum(Total_Time_Conditional) will give you expected result.

crosstab report how to calculate specific columns values and subtract from row total

am stuck at a point that in Crosstab report, i need to have sum of only two column's value and subtract the total by the value what should i do?
as in below,
Product 1 Product2 Product 3 Total
----------------------------------
Cust 1 4 5 2 11
Cust 2 5 9 7 19
I want to sum values of "Product 1","Product 3". then subtract from row total=> Total
LIKE
[4+2]-11=>TOtal.
and want to repeate this for each customer..
anyone please help me out.
I'm not sure when embedded summaries were introduced but I am pretty sure that your version of Crystal has this functionality. If not I apologize ahead of time. I have only been using this method for a few months now and it is quite confusing at first. At least to me but it has come in quite handy.....
I am making the following assumptions about your crosstab. Make name changes as you need to
row {yourtable.CustID}
Column {yourtable.product}
summarized field {yourtable.cost}
In the top left of your crosstab, right click go to advanced calculation and select calculated member
Select New and enter a description
For Type: Select Column
For insert Evaluation: Select After
Click edit insertion value and enter
CurrentColumnIndex=(GetNumColumns-2)//This will insert a column just before the total column
Click edit header formula and enter in quotes what you want to call the column
Select the content in Value Formulas then click Edit Value formula and number value
Save and close then exit the calculated member expert
Your crosstab should now have a new column
Right click the value go to Calculated member and select edit calculation formula
Enter this formula
(
GridValueAt (CurrentRowIndex,0 , 0) // Product 1 value
+
GridValueAt (CurrentRowIndex,2 , 0) // Product 2 value
)
-
GetTotalValueFor "yourtable.product")
NOTE: Geez it is hard to post on this site!
well after thinks long on it I've have done......
1st be clear that crystal report 10 is not offer following function
"CurrentRowIndex", "GridValueAt"
 
that's why above solution by "CoSpringsGuy" is not applicable.......
as we have two tables. 1 customer and 2nd for products and by both we generate crosstab with summarize field of product_sold (Qty) and 2 crosstab columns “Product.name”  and sub column product. Type
Now we want to sum value under the product.packing type =”Pilot”  of  product sold to each customer and subtract the sum-up from grand total of all products (product type “Normal” and “Pilot”)
For this problem 1st we have to work on formatting formula at crystal runtime and manipulate to “Display string” of summarize field
And then we will edit totals i.e very last column
1st edit summarize filed “display string” with the help of following code
Global CCust As String to keeping last customer for teli new customer name
Global Ccol As String ' tht is for keeping last column/product.packing type and teli with new col
Global Rndx as number ' this is for generating index of the row
Global totperx(22) as number ' is to hold the currnt value of cell and adding with previous value
' and i imagen that number of customers will less then 22 otherwise you can take unlimited array
Whileprintingrecords
if (CCust="") then
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
Rndx=1
formula="new"
end if
if CCust<>gridrowcolumnvalue("Viw_Prod.Packing") then
formula="same"
Rndx=Rndx+1
else
formula="Newag"
end if
if Ccol<>gridrowcolumnvalue("Viw_Prod.Packing") then
Rndx=1
end if
if gridrowcolumnvalue("Viw_Prod.Packing")="Pilot" then
totperx(Rndx)=totperx(Rndx)+currentfieldvalue
end if
formula=totext(currentfieldvalue,0,"") ' despite of cstr function totext will change 45 to 45 while cstr changes 45 to 45.00
CCust=gridrowcolumnvalue("Table_Cust.Name")
Ccol=gridrowcolumnvalue("Viw_Prod.Packing")
now we will edit "Display String" of grand total column
Global my as number
Global totperx(22) as number
whileprintingrecords
if my<1 then
my=1
end if
formula=currentfieldvalue-totperx(my)
my=my+1