Crystal Reports: multi-value parameter to filter on substring value - crystal-reports

I have a Crystal Reports 2008 file with a string parameter that accepts multiple values. I need to use this in the record selection. I know generally you can do something like
{MyTable.MyField} In Join( {?MyParam}, "," )
but I need users to enter values that may appear in a much longer field value, i.e., by substring. I tried
NumberVar index;
For index := 1 To UBound( {?MyParam} ) Do (
{?MyParam}[index] In {MyTable.MyField}
)
and while it doesn't throw an error, it doesn't seem to have any effect on record selection (that is, the report displays the same number of records regardless).
To be more specific, say MyTable has three records, and MyField contains the text Red Blue Green, Green Yellow Purple and Red Yellow Orange respectively. With the parameter, the user should be able to type the values red and blue in order to filter down to the first and third records.

Create a custom formula to compare two arrays for over-lapping values:
//Array_Overlap
Function (Stringvar Array a0, Stringvar Array a1)
Local Numbervar i;
Local Numbervar j;
Local Booleanvar found:=false;
For i := 1 To Ubound(a0) Do (
For j := 1 To Ubound(a1) Do (
If a0[i]=a1[j] Then (
found:=true;
Exit For;
)
)
);
found;
Reference it in your record-selection formula (RSF):
// space delimited
AND Array_Overlap( Split({MyTable.MyField}, " "), {?MyParam} ) = TRUE

Related

concatenate string in crystal report

I have a variable dItemDesc defined in the Group Footer:
whilereadingrecords;
stringvar DispItemDesc;
DispItemDesc := DispItemDesc + "> " + {Command.ItemDesc}
The display for the first record is correct, but following records just continue to concatenate the string. Where / how would I reset the variable to blank?
Create another formula as a reset. Place it at the stage you'd like it to clear out. (Presumably one section below the current Group Footer, or in the Group Header.)
whilereadingrecords;
stringvar DispItemDesc;
DispItemDesc := ""

Crystal Report, Grouping Rows into single Row on the basis of Criteria

I have a crystal report, which shows different fruits data on the basis of Fruit Name Group.
I am attaching a screen shot which tells the clear requirement, I want to group same type of fruits merge all into one rows and sum of their values as well.
I need help, can someone suggest a better idea?
1) Add a Formula Field
This formula field, should return
- real FruitName for the cases you don't want to group,
- a fake FruitName for the rows you want to group together.
Something like this (drag'n drop fields into Formula editor):
if {commandname.FruitName} <> 'Orange' AND FruitName <> 'Lemon'
AND FruitName <> 'Grape Friut' then {commandname.FruitName}
else 'Orange, Lemon, Grape Friut'
2) use Group Expert to create a Group based on the new Formula Field
3) suppress details and show in Group Header or Group Footer Totals for each field
I am not able to understand completely you problem.. but try below solution: If it is useful use it else discard
Concatenate Fruit Names: Create one formula #Fruit
Local StringVar orange;
Local StringVar Lemon;
Local StringVar Grape;
if <<databasefield.fruitname>>="Orange"
then orange:=<<databasefield.fruitname>>
else if <<databasefield.fruitname>>="Lemon"
then Lemon:=<<databasefield.fruitname>>
else if <<databasefield.fruitname>>="Grape"
then Grape:=<<databasefield.fruitname>>;
orange+Lemon+Grape;
Summing the values: Create one formula #Weight
Local NumberVar orange;
Local NumberVar Lemon;
Local NumberVar Grape;
if <<databasefield.fruitname>>="Orange"
then orange:=<<databasefield.Weight>>
else if <<databasefield.fruitname>>="Lemon"
then Lemon:=<<databasefield.Weight>>
else if <<databasefield.fruitname>>="Grape"
then Grape:=<<databasefield.Weight>>;
orange+Lemon+Grape;
Edit:------------------------------------------------------------------------------------
you need to have grouping something like below.
Fruit name Fruit Type
Orange a
Grape a
peach b
apples c
now when you group by fruit type and apply the formula I have provided then you can get desired results
I have done with other way, calculated these fruits values as a separate row, sum up all the values and then applying union , In union I have concatenated the fruit names using COALESCE function

Crystal Report Formular always return Boolean

iN my Crystal Report i have two columns of currency data types. I want to add a formular to the column a . i.e "WHEN A CURRENCY IN A is > THAN B, THEN The value of A should euqal the value of B ". I wrote my formula as below
currencyVar formular := {ProcName.coll};
IF({ProcName.coll} > {ProcName.ref})
Then
formular = {ProcName.ref}
AND
IF({ProcName.coll} > {ProcName.ref})
Then
{ProcName.coll}= {ProcName.ref}
Both yielded the same boolean values.When I saved and named the formula above, i then insert the formula to my column . However, the result are all boolean True/False. I am ot sure how this happened i check the data type of the formula is indicating boolean as well.
This is because you're testing equality not assigning the value as you wish to do. Change your last line to a statement of assignment by adding a colon before the equal sign:
...
formular := {ProcName.ref}
// ^

This field cannot be summarized crystal report error

I've got the problem about crystal report. I've created one formula field called PAT_DEP and formula is as follow.
Local NUMBERVAR PAT_DEP_AMT := 0;
IF NextIsNull({MYOBJ.PAT_DEPOSIT}) = TRUE THEN
(
IF {MYOBJ.PAT_DEPOSIT} = PREVIOUS({MYOBJ.PAT_DEPOSIT}) THEN
(
PAT_DEP_AMT := 0;
)
ELSE
(
PAT_DEP_AMT := {MYOBJ.PAT_DEPOSIT};
);
)
ELSE
(
IF PREVIOUS({MYOBJ.PAT_DEPOSIT}) = NEXT({MYOBJ.PAT_DEPOSIT}) THEN
(
PAT_DEP_AMT := ToNumber(0);
)
ELSE
(
PAT_DEP_AMT := {MYOBJ.PAT_DEPOSIT};
);
)
Then I've created another formula field called TOT_PAT_DEP and formula is as follow like summarized above formula field.
TOTAL_PAT_DEP := SUM(#PAT_DEP)
But got crystal report error This field cannot be summarized crystal report error. Please help me how come I got this error.
Based on your explanation and formula, it looks like you have a one-to-many relationship which is causing you some difficulty. Let's take an example:
Order Table
Order #, Total, Paid
Order Items Table
Order #, Line #, Description
When you join the two tables you can no longer sum the total/paid columns because they will be multiplied by the number of order lines.
The way to overcome this is to create a group using the key. In my example you would group on Order #. You can then create a running total to sum the total/paid columns but will only evaluate on the change of your Order # group.
Does that make sense?

For each crosstab column, highlight maximum value

I'm trying to highlight the maximum value in a Crystal Reports crosstab column, per column, i.e. show the best performing salesman in each month.
It seems like a fairly basic requirement, but I can't figure it out! The Highlighting Expert would seem to be the obvious answer, but it only works if you have defined criteria (e.g. Gross Sales > 120,000), and I'm not interested in highlighting the Totals at the end of the columns/rows....I just want the highest value row per column.
This is much more difficult than it needs to be...
Add this text to the summary field's "Tool Tip Text" conditional-formatting formula:
// this assumes that there is a Total column and that it is the left-most column.
Numbervar max:=0;
local Numbervar col;
// exclude (left-most) total column
for col := 1 to GetNumColumns-1 do (
local numbervar value := GridValueAt (CurrentRowIndex, col, CurrentSummaryIndex);
if value > max then max := value;
);
ToText(max,"#");
Then add this text to the same field's "Style" conditional-formatting formula:
Numbervar max;
If GridValueAt (CurrentRowIndex, CurrentColumnIndex, 0) = max Then
crBold
Else
crRegular