Minimum & Maximum Values in Crystal Reports 2008 Column - crystal-reports

Say I have this column returned in a command for Crystal:
deposit_no
123
130
125
124
126
127
128
129
and I need to have this in the report title:
Includes deposits between 123 - 130
I've tried a running formula for minimum and maximum and they aren't returning the correct values no matter how I manipulate them. I've tried evaluate for every record, on change of the deposit_no field, etc. I have no grouping on this report.
Edited to add:
While I preferred to handle this on the CR side of things, I changed my command to include what mson wrote below. So technically, mson had the correct answer.

create a stored procedure or view that has the information you want. access the stored procedure or view through crystal reports.
crystal reports is a hindrance to properly coding anything.
the unexpected result you are getting may be because the column is not numeric. often, number values are stored as varchar/nvarchar. this is done especially for fields like zipcode/phone number/etc. where the value may be numeric, but you would never do math on them.
in any event, here are the snippets you can use to build in sql server (and then call from crystal)
select min(coalesce(cast(deposit_no as int),0)) as min_deposit from tableA
select max(coalesce(cast(deposit_no as int),0)) as max_deposit from tableA

Came across this while searching for the same thing, and would like to add to SqlACID's answer which does work.
You can do this in your formula editor.
'XX'+totext(Minimum ({YY.Num}), 0, '') + '-XX'+totext(Maximum ({YY.Num}), 0, '')

Create a formula field using summary functions for minimum and maximum of the deposit_no field, then drag the formula field to the page header

Related

DSUM function in crystal reports?

I am trying to convert an old Microsoft Access report into Crystal reports. I have everything working perfectly except for this last small detail. The Access report uses a DSUM function within an if statement for one of the fields on the report.
After much searching, I've determined that CR doesn't have anything similar.
Here's basically what I'm dealing with.
I have a proposal report. In the details of the report I print the qty, description, and a couple of price fields.
The data looks like something this:
Proposalnum Partitem RolltoItem Unitprice
18611.............1.......... NULL........0.00
18611.............2......... NULL.......17225.92
18611............3............ 2............156.90
18611............4............. 2............482.05
What I need to do is when I print a specific part, I need to query through the rest of the records to find the parts that have a matching number in the rolltoitem field and add the unitprice to the part I'm printing.
So in this example when I print partitem #2, I need to add the 156.90 and the 482.05 from parts 3 and 4 to the 17225.92 so I print a total of 17864.87.
Is there any way to do this?
As far as i know, there is no such function.
But I would try this.
The general idea is: group the data by ProposalNum and use a subreport to select the "children rows" and sum the "children prices".
Details:
Create an empty group section by PartItem.
If you want to show only items where RoolToItem is null, use a suppress function for this case.
In the details section, put a subreport. The data source of the subreport would be the same of the main report.
Change subreport links to select data in subreport based on fields: PartItem in the main report = RolltoItem in the subreport.
Pass other fields to the subreport without select data: ProposalNum, PartItem, UnitPrice. I think you need to create parameters in the subreports before doing that - example: ParentProposalNum, ParentPartItem, ParentUnitPrice.
Create a new formula: ParentUnitPrice + Sum ({YourDataSource.UnitPrice})
Put the formula in the subreport footer a long with the other fields. Maybe: ParentProposalNum, ParentPartItem, formula.
It is a theoretical solution. I hope it points out to the right direction.
If you are trying to sum the Unitprice column for all items that have the same value in Rolltoitem, you could do this with a SQL Expression Field. The code would look something like this. My Where clause may need tweaked though since I'm not sure what your database structure looks like.
(
Select Sum("YourDataBaseTableName"."Unitprice")
From YourDataBaseTableName
Where "YourDataBaseTableName"."Rolltoitem" = *currentRolltoitemValue*
)
Syntax can also vary for SQL Expression Fields based upon what type of database you are using. The syntax I provided is fairly general, but should work on SQL Server.
EDIT: Adding example with explanation of how it works.
Here is one of my SQL Expression Fields from a crystal report that prints a Bill of Lading for shipped goods.
(
Select Sum("SHIPMENTS"."PALLET_COUNT")
From SHIPMENTS
Where "SHIPMENTS"."BOL_ID" = "BOL"."ID"
)
In my database the BOL table is the starting point. A single BOL can contain 1 or more SHIPMENTS, and a single SHIPMENTS can contain one or more PRODUCTS.
Top level grouping is on BOL.ID. The PALLET_COUNT is found once and only once on each SHIPMENTS. I also had a sorting requirement for the data in the details section that prevented me from using a Running Total Field.
This allows a BOL with 2 SHIPMENTS that contains a total of 3 products to look like this:
BOL.ID SHIPMENTS.ID SHIPMENTS.BOL_ID PALLET_COUNT PRODUCT.ID
1 10 1 2 XXX
1 9 1 1 YYY
1 10 1 2 ZZZ
The correct PALLET_COUNT for this BOL should be 3, since PRODUCTS XXX and ZZZ are in the same SHIPMENTS and the PALLET_COUNT is duplicated because of its relationship to the PRODUCTS.

Using running totals in formulas - Crystal reports

I have created a set of running totals looking for specific fields in a database.
If these fields are located, a subsequent sum is performed to calculate the total for that field. e.g. Field to Summarise - DB.Field.Value-Sum. Evaluate - Use a Formula-Field Name ='1'
This sums the totals for this field. The issue is that I have many running totals doing this, and what I want to do is add these together to provide a total for all of these. Currently I have a formula that uses each field with a '+' between each. This appeared to work fine, but when tested against a record where some of these fields are blank, the subsequent formula displays nothing.
Any advise on what I should do here/ am doing wrong?
Thanks
It sounds like a null record (empty value) is breaking your running total. You have a few options
Use a formula to check for, and replace a null value with another value (Zero, for example) and then use that formula in your running total calculation
if isnull({Command.Decimal}) then 0 else {Command.Decimal}
Use a SQL expression to replace null with another value Isnull(Tablename.Columnname,0) - use this in your running total
On the running total, under "evaluate" select Use a formula and use this formula not(isnull({tablename.columnname})) -- If the record IS null, the running total does not evaluate it. It will be ignored by the running total.

Using LIKE in Multi-Value Parameter in Crystal Reports 2011

I am developing a report in Crystal Reports 2011 that has 3 sub-reports pulling data from 3 different databases. I have a Multi-Value Parameter (String) in the main report that passes the input values to the 3 sub-reports which have the same Multi-Value String Parameter.
Sample Input Values are:
P000000030,
P000000930,
P000001730
The user does not want to input the leading alpha character and preceeding zeroes. They want to input the following:
30,
930,
1730
The sub-report pulls all of the records successfully if the user puts the entire string value in with the following Record Selection Criteria, but it does not work with the partial strings input:
{Command.Puchase Order} in {?Pm-?Reference}
Can anyone advise the syntax needed to pull the data in the subreport with the substrings as inputs?
Thanks in advance!
Thank you for your input guys!! I took a bit from everyone and came up with the following solution:
Create a column in the datasource that trimmed out the desired value --> ltrim(regexp_replace(a."po_num",'P',''),'0') as "Puchase Order2"
Modified my Record Selection Criteria to select for either column --> {Command.Puchase Order} in {?Pm-?Reference} or {Command.Puchase Order2} in {?Pm-?Reference}
I really appreciate your input! I am able to deliver the desired solution with your aid.
go ahead and create a formula that calculate the length of your parameter(len({?Pm-?Reference})) and place it suppressed on your report header. Then put below in your record selection formula
right({Command.Puchase Order},{your length formula}) in [{?Pm-?Reference}]
You could add the "number only" version of [Puchase Order] to your datasource...
cast(cast(right([Puchase Order], len([Puchase Order]) - 1) as int) as varchar(9))
as [Puchase Order Number]
...then use that in the select expert. I'm getting the number without the leading P, casting to int to remove the leading zeros, and then back to a varchar for the string comparison in Crystal.
You could do the same with a formula in Crystal reports. Then reference that formula in the select expert. Downside is having to repeat that in all 3 sub reports.

Dynamic parameter not pulling list of values out of field

I have two kinds of parameters in a specific Crystal Report I am making -- two dates that I use directly in the SQL query, and a parameter that will filter the report based on sales reps within the query.
I defined the two dates (date1 and date2, if you will) when I created the command, and those work fine. However, when adding the dynamic parameter to choose which values I want for the 'sales rep' field, only a text box appears, meaning the parameter list hasn't been generated dynamically like advertised.
I know the reason for this -- the query hasn't run yet, so there aren't any dynamic values to pull. The date range is a necessary evil as well, since the report takes five minutes to run if a date range isn't set due to so many older records (which need to stick around do to history purposes).
Is it possible to generate this list dynamically at all, or am I stuck having to update a list with static values?
Thanks.
To get the dynamic parameter to work, you'll have to add whatever table to the report that contains the 'sales rep' field. You can pull the table in next to the SQL Command that you're creating, and just link them however you want with an outer join so as not to limit your records (You could even not link them at all, but Crystal will complain about having "Multiple starting points" or whatever.
Now you can pull the sales reps into the dynamic parameter and use it in either the SQL Command itself as a parameter, or you can just use it in the record selection formula to filter results from the SQL Command. In both cases, CR will query the database twice; the first time to simply get the entire list of reps and the second time to run the SQL Command.
The main takeaway here is that the table, not a command, needs to be in the report in order to be a candidate to populate dynamic parameters... even if you won't use that table again in the report. Hopefully that helps, even if it is 7 months late.
Finally figured this out:
Using SQL create the stored procedure that gathers your report data. This stored procedure CAN NOT have parameters. It must generate all your report data upon execution
Example 1: Exec MyReportStoredProcedure
Create another stored procedure to gather your parameter list values. Again no parameters used in the stored procedure.
Example 2: Exec MyCrystalParameterList
In Crystal Reports under Database -> Database Expert add both stored procedures (Called tables) to the "Selected Tables" section. Click "OK". Crystal will then try to make links between the two tables. Click "Remove All Links". Click "OK" on all link warnings that follow.
Now build your report using the columns from MyReportStoredProcedure
Run you report. You will NOT get prompts to enter parameters. All possible data will be displayed in the report.
* Now time to link the parameter to the data. *
Crystal reports will execute both stored procedures as soon as you open the report.
Crystal reports does not pull data based on the parameter like reporting services (SSRS).
Crystal filters the data based on the parameter value you selected after all data is gathered.
Running MyReportStoredProcedure returns the following:
1 Stop XX 7A [columns5] [columns6] [columns7] [columns8]
1 Gone CC 88 [columns5] [columns6] [columns7] [columns8]
1 Gone CC 88 [columns5] [columns6] [columns7] [columns8]
2 Nice XX C3 [columns5] [columns6] [columns7] [columns8]
3 Loop EE C3 [columns5] [columns6] [columns7] [columns8]
3 Loop DD C3 [columns5] [columns6] [columns7] [columns8]
3 Loop DD C3 [columns5] [columns6] [columns7] [columns8]
...
... 700,000,000 Additional records
...
Running MyCrystalParameterList returns the following:
1 Stop XX 7A
1 Gone CC 88
2 Nice XX C3
3 Loop EE C3
3 Loop DD C3
>> A distinct list of values only 5 rows <<
* Link the parameter data column to the corresponding report column *
Now link the parameter Column1 to the report column1. This link ties the main report values (MyReportStoredProcedure) to the parameter values (MyCrystalParameterList).
In Crystal Reports under Database -> Database Expert Click the tab called Links.
In this section you link the tables/columns together. You could have done this in the steps above but for better understanding I want you to do it here after showing the data returned for both stored procedures (tables).
* Create your cascading parameter *
In Crystal Reports find the Field Explorer panel. Usually its on the right side of the screen.
Now Right click [Parameter Fields] and select [New]
Name the parameter
leave the type as [String]
set "List of Values" to [Dynamic]
set "Choose a Data Source" radial button to [New]
In the table below the radial button, click in the first row under the word "Value"
A drop down showing both tables will be displayed ([MyReportStoredProcedure and MyCrystalParameterList])
Select the columns for your first parameter from your MyCrystalParameterList stored procedure (table).
Your column is now listed in the first row.
Now click the next row and select your next column from your parameter stored procedure (table).
repeat until all of your desired parameters are displayed in the table rows.
On the right side of this table you will see a column called "Parameters" there is text in this column for each row.
Click each field in the "Parameters" column and a parameter is created in Crystal report that corresponds to your parameter stored procedure (table) column.
Click "Okay" to close the "Create New Parameter" dialog box.
If you run your report, you will be prompted to select values for your parameters and the parameters will list available values.
ALL OF THE DATA WILL BE RETURNED IN THE REPORT!!! We are not done.
* Last step (Finally!) *
Tell Crystal reports to filter the report data based on the parameter value.
In crystal reports, click on Report -> Select Expert -> Record
A "Chose field" dialog box will display
Fields panel Look for the report stored procedure and expand it so the columns are showing
Select one of the columns that linked to the parameter stored procedure (table).
You will now see a formula dialog box with a default value of "is any value".
change this value to "is equal to"
A drop down box will appear to the right.
The drop down box will show your parameters!!!!!!
Select the parameter that corresponds to the report field you select.
repeat for all of your parameters.
Now run your report. The data is now filer by your parameter value!!
You are done!!!! Thank GOD!
Note:
You can make a single stored procedure for each parameter. Just add them to the report using Database Expert.
In my example I made one stored procedure that pulls all possible parameter combinations.
DO NOT ADJUST YOUR REGISTREY SETTING AND MAKE CRYSTAL REPORTS READ MORE THAN 1000 RECORDS!!!
Your report stored procedure can return 1 Billion records but your list of parameters should not be more than 1000 unique values.
You cannot build your parameter list from the report stored procedure because crystal reports will only look at the first 1000 records.
Your parameter list must be a separate stored procedure that pull distinct values.
* You have the foundation, Now build the rest. Good luck. *

Crystal Report-Running Total

I have a problem with running Total in Crsystal report9
if their is no values available for a Paticular field how can we return the running total as '0'
Instead of display the Running Total directly in your report create a Formula Field based on the Running Total and drag it into the report.
Your formula should look like this (Crystal Syntax)...
if ISNULL({#RunningTotalField}) then
"0.00"
else
ToText(RunningTotalField, 2)
If there is no data for that particular group, then Crystal won't show it easily. Your options are :
1) Use subreports to display the values for a particular group, and keep the main report just looking at the table(s) containing the group headers.
2) Use a stored procedure as the source so you have full control over the SQL that is run.
The problem is that as soon as you use a field to group, Crystal will only return records where that field has been used. If it was simply in the Details section you could modify the link to a LEFT JOIN and it wouldn't matter, but the group forces the INNER JOIN which means the groups without data are not returned.
Unfortunately Running Totals don't show up if there are no records that match your criteria. An alternative is to use a set of formulas calculated in various sections of the report. The technique is widely described in the Crystal literature. For example, this TekTips gives a very succinct overview of your options.
You set up an initialising formula in each header, with the evaluation time directive "WhilePrintingRecords". This approach was the only one available for doing running totals in the "good ol' days" before RunningTotal objects were available.