Change Group Name in Crystal Reports to non-Database Value using Formula - crystal-reports

I am looking to change the group names in a crystal report to a specified text value not located within the database.
e.g. i have a 'status' field that can either be 'i' or 'a'. I would like these to display as 'inactive' or 'active' in the group headings. The code i currently have in the 'Use a formula as group name' is:
stringvar newGroupName;
if (groupname = "I") THEN newGroupName:= "Inactive" ELSE
if (groupname = "A") THEN newGroupName:= "Active" ELSE
newGroupName:= groupName;
newGroupName
However this says i am passing too few arguments for the groupName reserved word.
Have looked on the net but have not found anything for defining non database names using the groupname function. Any help greatly appreciated.

Just to add, I always add a standard formula to the formula list to calculate the group names :
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown'
Then in the group name formula in the group expert I refer to the formula like {MyGroupName}
This makes it much easier and quicker to edit the names but also will not be lost if you edit the group field (very useful if you have a large amount of code).

Make sure you pick fields from the window they will appear like {table.field} etc
There is no need for variable here just do something like:
if {table.field} = 'I' then
'inactive'
Else if {table.field} = 'a' then
'active'
Else
'unknown';

Related

Count if "YES" in 1 field or another in Tablean

I am trying to create a calculated field in tableau that will count if one field OR another contains 'yes' - and then add the YES's together as a value.
I have tried CASE WHEN, IF, COUNTIF but I am having trouble as I have to have the OR in the calculated field.
Here is my last attempt that also failed:
COUNTIF([M-CROSSC (Cross Country)]) = 'YES' OR ([W-CROSSC (Cross Country)])= 'YES' THEN '1' END
Try this. Put the if statement inside the count().
COUNT(IF [M-CROSSC (Cross Country)] = 'YES' OR ([W-CROSSC (Cross Country)]= 'YES' THEN '1' END)
edited to remove extra ')' after each dimension.

How to create a drop down or multiple select filter in dashboard that will filter all worksheets?

I have null and non-null values in my dataset. I would like to create a drop down which will consist of -Display All, Null or Non-Null values. This should filter the dataset so that all worksheets in the dashboard are filtered out based on it. How shall I proceed?
A parameter will help you accomplish this.
Create... > Parameter > String > List > ["All", "Non-Null", "Null"]
From there, create a calculated field which references the parameter.
If [Parameter] = "Non-Null" Then
(If IsNull([Nullable Field]) = False Then 'Show' Else 'Hide' End)
ElseIf [Parameter] = "Null" Then
(If IsNull([Nullable Field]) = True Then 'Show' Else 'Hide' End)
Else 'Show'
End
Finally, place the newly created calculated field on filter and select only 'Show.' To filter all worksheets, right click on the filter and select Apply to worksheets > All using related datasource or specific sheets of your choosing.

Nested if else Condition in Crystal report

I have a .rpt file , with a view datasource . I have four parameter which i use in filtering the selection. I have written my selection formula like below.
if ({?actype} <> "All") OR ({?actype} <> "All") OR ({?collectorname} <> "All") OR ({?batchno}<> "All") Then
(
if {?actype} <> "All" Then
{CollectorPerformance.accountType} = {?actype};
if {?collectorname} <> "All" Then
{CollectorPerformance.realname} = {?collectorname};
if {?batchno} <> "All" Then
{CollectorPerformance.batchno} = {?batchno}
and
{CollectorPerformance.clientid} = {?clientid}
and
Date({CollectorPerformance.paymentdate}) >= Date({?from})
and
Date({CollectorPerformance.paymentdate}) <= Date({?to})
)
My issue with the formula, above is that it does not filter by realname and actType. I understand the reason is because the key word "and" is missing . however, it filters the batchno correctly> please how do i make it filter by the remaining two if's ? any help would appreciated.
A selection formula has to be one long valid boolean statement, which is, I think, what you were already suggesting when you say the "and is missing". So in order to fix the first half, you just need to translate those statements into one simplified boolean statement instead of individual statements (those that end in a ';').
({?actype}="All" or {?actype}={CollectorPerformance.accountType})
and
({?collectorname}="All" or {?collectorname}={CollectorPerformance.realname})
and
({?batchno}="All" or {?batchno}={CollectorPerformance.batchno})
...
For each parameter, a user can either select "All" or enter a specific value to filter by. If "All" is selected, that particular portion of the statement (The part that looks like {?Parameter}="All") will evaluate to True and no filtering will be done. Otherwise, only records matching the entered parameter value will return True.

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

Dynamic grouping in crystal reports

So I have these 3 table/views in my database.
Table
id
template
View1 // the ids in this view have a corresponding id in table if template = 1
id
type1
View2 // the ids in this view have a corresponding id in table if template = 2
id
type2
So in my report, I want to select all the ids... and then group by template, and then group by type. I can do this for one View at a time by setting up the group to be either View1.type1 or View2.type2. But, I want it to group by View1.type1 if template is 1 and then I want it to group by View2.type2 if the template is 2.
So I made a forumla called type, and changed the group to that formula.. So I am first grouping by template, and then by type (my formula). If I set the formula for type as below:
formula = {View1.type1}
Then it works as expected and I see the correct grouping. It also works if I only do it for View2.type2.
However, when I do this:
if {Table.template} = 1
formula = {View1.type1}
else
formula = {View2.type2}
This returns no data for my grouping. Even if I do this:
if 1 = 1
formula = {View1.type1}
else
formula = {View2.type2}
This also returns no data. How is dynamic grouping supposed to work? I am missing something? I guess at the worst case I can make another view in my database or even use subreports... but I was hoping to have it work like this... I greatly appreciate the help guys!...
UPDATE:
So I can do formulas such as this one:
if {View1.type1} = "" then
formula = "[Undefined]"
else
formula = {View1.type1}
end if
It looks like I only have issues when I try to use a formula with the 2 views...