Sort based on specific field within a group - crystal-reports

I have a report which I need to Group by type but the rows under the group should be sorted based on specific field code. from the below eg. the Reason field needs to be sorted in the order NSL,RWR,PAL,CON order within the grouping.
TYPE DATE NAME CODE
**CEM**
Cem NSL
Cem RWR
Cem PAL
Cem CON
**FUN**
FUN NSL
FUN RWR
FUN PAL
**IP**
IP NSL
IP RWR
IP PAL

The easiest way to do this is to create a formula "Priority" like this:
if CODE="NSL" then 1 else
(if CODE="RWR" then 2 else
(if CODE="PAL" then 3 else
(if CODE="CON" then 4 else 0)) )
and put in into the detail row of you report.
Then goto "Report" menĂ¹ ->"Record Sort Expert" and sort the detail with your formula "Priority"

Related

Accessing the ATTR field troubleshooting in Tableau?

I am working on Tableau server but I believe the problem I am facing does not correspond to tableau server specifically.
I am using two data sources ds1 and ds2 which are joined using the dimension Id . ds1 has a field city and ds2 has a field district. There is only 1 city corresponding to each Id but there can be multiple district corresponding to an Id .
I have created a calculated field Points in ds2 which is described in the code segment.
I have researched from different sites and blogs (including tableau support). I came to a close possible reason behind this and I might be wrong . The ATTR function which works on row level and identify if a row is unique then it outputs the dimension otherwise it outputs '*' . I think when I joined those two tables the district dimension in ds2 might have the '*' instead of actual district values, so it might not be able to compare the conditions in if statements of Point .
//Point//
IF [city] == "Delhi"
AND [district] == "Dist1"
AND [district] == "Dist2"
THEN "100 Section"
ELSEIF [city] == "Mumbai"
AND [district] == "Dist11"
AND [district] == "Dist12"
THEN "200 Section"
ELSE "Other Section"
END
When I insert data which satisfy the conditions in calculated field, it is going in Other section of the Point .I want it to go in desired section.
For instance
Id = 19
city = Delhi
district = Dist1
district = Dist2
district = Dist3
It should go in 100 Section but it is going in Other Section . What modifications should I do or add to make the Point work properly ?

Grouping and Sorting by Odd and Even Numbers

I am trying to create a report which has addresses in form of house Nbr and street Name. I want to group all address by street name and then order them by house nbr which is a string but should sort like a number. Ideally i would like the odd ascending and then the evens descending so that my list would look like
1,3,5,7,9 .... 8,6,4,2
How would i go about this ? I created first group on street name and then 2nd group on house number with a formula for sorting of nbrs
i created a Formula Field OddEven with
ToNumber({tbl_FarmMaster.sano}) MOD 2
but i am having hard time applying that to my group
Create two formulas like below. Let's call them oddFirst and negativeEven.
oddFirst formula:
ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
1 //it is odd
else
2 //it is even
negativeEven formula:
if ToNumber({tbl_FarmMaster.sano}) MOD 2 == 1 then
ToNumber({tbl_FarmMaster.sano}) //it is odd
else
-ToNumber({tbl_FarmMaster.sano}) //it is even, note the negative sign
Then create two groups to sort:
first by the formula oddFirst
second by the formula negativeEven
Show the {tbl_FarmMaster.sano} field.

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

How can I order a group, based on a summary field of a subgroup

I have a report which has essentially
Order
OrderDetail 1
OrderDetail ..
OrderDetail n
These details can have parts and/or labour costs associated with them.
Currently, I group based on OrderId and then have the OrderDetail information in the details section of the report. This works perfectly.
However, now I need to group the Orders based on two criteria OrderType and LabourCost of the entire Order. I have put together a quick formula to determine order.
if(Sum({order.Labour}, {order.OrderId})> 0) then
if({order.type} = "type1") then 1 else 2
else
if({order.type} = "type1") then 3 else 4
Basically, if it should be sorted based on labour then on type. (the Sum({order.Labour}, {order.OrderId}) sums the labour grouping based on the orderid)
However when I go to the Group Expert and add the group by field to my formula and then preview my report it spins (I cancelled the preview after a minute). If I remove the Sum portion of the formula then it takes less than a second.
Is there a way to order this report?
How I would approach it:
First, create a sql-expresssion field that calculates the labor total for each order:
// {%TOTAL_LABOR}
(
SELECT Sum(Labour)
FROM OrderDetail
WHERE OrderId=Order.OrderId
)
Next, create a formula field:
// {#OrderGroup}
if({%TOTAL_LABOR}> 0) then
if({order.type} = "type1") then 1 else 2
else
if({order.type} = "type1") then 3 else 4
Finally, create a new group, based on the formula field, ensuring that it groups before the order group. You can suppress the group's header and footer if desired.

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

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';