Is there a way to have number type parameters blank? - crystal-reports

I'm creating a demographics report where users can choose what demographics they want to include on the report. One of the options is age range where the user can type in their own figures. Everything works except when the age range parameters are not used. The others can be blank as they are string types but the age range parameters are number types because I need to use them to do counting. Is there a way to use number type parameters but allow them to be blank if necessary?
I tried changing the type to string and then running a ToNumber formula to use the field for my needs but I get the same error. I also tried suppressing any fields that use number parameters but trying to say suppress is Not HasValue but that didn't work either.

Related

Group data based on different size

I am trying to make a report in which I need to show data based on Width groups. Below is an example of data & the required output. I'm unable to make a group which can give this required output. If someone can help please.
The easiest way to accomplish your grouping needs for this data set would be to create a new Formula Field that evaluates the values of the Width data field for each record to determine which group the record belongs within, then do the grouping on this new formula field.
You formula field will look like this.
Select {WIDTH}
Case 400 to 600 :
"G1"
Case 601 to 849:
"G2"
Case 850 to 1049:
"G3"
Default :
"Default text or error message text goes here"
You will likely need to adjust the integer values I'm used in the Case statements to evaluate the WIDTH field. The text that goes into the Default case is up to you. In fact, if it works logically with your needs, you could eliminate the Default case entirely, as it is not required. However, it is good practice to ensure the Switch statement always returns a value, even if that value is text to indicate that something unexpected occurred. This allows your users to easily recognize a bit of a data that may be out of range for the grouping of the report so the report can be modified or the data can be corrected, whichever is the most appropriate action.
The other 3 columns in your required output appear to just be counting the number of records within each group that have a diameter within a range. To get this output you can use Running Total Fields with a Type of summary of Count and then use the range of values in the Evaluate section. The Reset section will be set to On change of group evaluating the group created by the formula field above. You will want to put a sort order on the diameter field though.

Creating Parameter field for # of days

In crystal reports I am trying to create a parameter where the user can enter number of days.
For example, I want the report to prompt with Enter Age Days: XX
The issue with this is that I do not have a field that stores days in the database. I just want the end user to be able to enter a number lets say 60, then store that number so that it can be used in report calculations.
Please let me know your thoughts
Thank you
Sarah
Creating number type parameter that is not linked to a database field
Parameters in Crystal don't have to be 'dynamic' (linked to data source column).
When you create a new parameter, the default is for a 'static' parameter.
Simply set the data type of the parameter to numeric and name it.

Jaspersoft Studio: Force input parameter of subreport to be entered manually

In my main report I get a (small) list of string values from the data base. I then want to use this list for selecting records in a subreport, along with other input parameters:
The user shall be able to select records based on a range of begin and end date -- this is easy using an input parameter of type java.util.Date with "Is For Prompting" set to true. Another criteria shall be one or more items from a list showing values from a data base field. I could define the list in the report template, but then I'd have hard-coded strings (filled from the data base, but at definition time only).
Now the dilemma is: If I define the input parameters in the main report, I cannot get the values for the list beforehand; if I define them in the subreport, I get no prompt at all, so there's no way to set any of them.
So the report requires values for start and end date, and a list of string values to select from (multiple itmes can be selected). This list shall be built from values from the data base. In the subreport all these values shall be joined into a filter for the records. A user shall be able to define the dates and select items from the list manually before executing the report.
Is there a way to achieve this?
After some more hours of trial & error, and some more research, of course, I found that the keyword is "Query-based Input Controls". This documentation describes their creation on the JasperReports Server. Such input controls can be edited in Jaspersoft Studio as well, however, they actually work on the server only. Anyway, this is the solution to my problem.

Dynamic List Input control in JasperReport 5

I have 100,000 account numbers. I want to randomly give any 5 (as per my requirement. Could be 1 or 2 or 20) account numbers and see the information about them.I have tried the following.
I tried with string input control, cascading input control with one string and one list parameters. But none of them works.
1) String Input Control: I tried entering the 3 random account numbers comma separated. But my query dosent accept the same since I have to use a list parameter and $X variable.
($X{IN,acct_no,test}).
2) Cascading Input Control: I thought let me take a string input control and a list list input control and use the string input control within the list input control. So I tried like the following.
Created a parameter and an input control with string datatype (where I can enter comma separated account numbers). The parameter name is $P{account_no}
Created a list parameter and an input control with list datatype as an multiselect query using the string parameter as below. The parameter name is $P{test}
select account_no from customers where account_no IN ($P{account_no})
Note that I have used the first parameter.
This works fine for only 1 account number and not for 'n' account numbers.
I also tried something like
select account_no from customers where ($X{IN,acct_no,account_no})
For obvious reasons this does not work.
I am using Jasper 5.0.1
Is there a way to dynamically populate a list based on the input values.
Could anyone kindly let me know how to achieve my desired output?
Any help would be appreciated.
Many Thanks.
The following did the trick.
SELECT customer_name FROM customers where account_no in($P!{account_no});

Problems converting a crystal reports running total string to a number

I have a problem with converting a running totals string to a number.
The running total is set to retrieve the maximum value of a field that contains results. It is reset with change of a group and evaluated by a formula so that only results from a specific test is used.
The result database field is a string since there are test with text results as well as tests with numeric results in the database. The test I'm filtering out only have numeric results (saved as string).
The running total works fine and gives the correct result, but I want to change it from a string to a number to be able to set the number of decimals and use rounding in the report, and this is where my problem begins.
As far as I can tell there is no way of using the format field in this case. (Which is resonable since it is a string field.)
I've tried using a formula field with the following formula:
if isNumeric({#P-LDL}) then toNumber({#P-LDL})
but that returns 0.00 for all non-null values even though the strings are nice things like "2.36" or "3.74" (without the quotes).
I've also tried the old school approach of resetting a global variable in the group head, assigning it a value in the details section when a post with the correct test comes along, and then finally display it in the group footer, but I get the same 0.00 result. I've tried both using a numeric global variable and do the conversion on the details-level, and using a string variable and do the conversion in the footer-level.
Solved it:
if NumericText(Replace({#P-LDL}, ".", ",")) then
ToNumber(Replace({#P-LDL}, ".", ","))
Stupid locales...