Talk with the Author
 Crystal Reports Forum : General Information : Talk with the Author
Message Icon Topic: Sorting by Parameter Post Reply Post New Topic
Author Message
twinkle
Newbie
Newbie
Avatar

Joined: 16 Jun 2008
Location: United Kingdom
Online Status: Offline
Posts: 32
Quote twinkle Replybullet Topic: Sorting by Parameter
    Posted: 11 Aug 2008 at 7:05am
I would like my user to sort the data by using the parameter.  However it does not work properly.  OuchCry
I have created a "String" Parameter and a Formula which is an "IF" statement so if the user selects turnover then the report sorts by turnover and if the user selects campaign it would sort by that else it sorts by campany name. 
 
Formula i use
If {?SortField} = "T" Then {Comp_Revenue}
Else
     If {?SortField} = "R" Then {comp_Campaign}
     Else
          {Comp_Name}
 
Please help!
Confused
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 11 Aug 2008 at 12:07pm
How is this not working? 
 
I suspect that you're running into a problem because the revenue field is a number and the campaign and name fields are strings.  Also, the sample you give above doesn't show the table names of the fields (they're should be in the format of {table.fieldName} or {@formulaName})
 
So, you need to convert the revenue to a string.  The challenge with this is that you need to format it correctly in order to have the data in numerical order rather than string order.  If you just use ToText({Comp_Revenue}) then you'll get this type of order:
 
1
111
12
2
21
etc.
 
So you need to right-pad the number with zeroes to have it in this order
001
012
111
002
021
 
In order to do this you need to know how many characters are in the maximum possible number.  For example, if I had a field that was defined as Number(6,2)  I would do the following:
 
right('000000' + ToText({Comp_Revenue}, 2), 6)
 
-Dell


Edited by hilfy - 11 Aug 2008 at 12:34pm
IP IP Logged
twinkle
Newbie
Newbie
Avatar

Joined: 16 Jun 2008
Location: United Kingdom
Online Status: Offline
Posts: 32
Quote twinkle Replybullet Posted: 12 Aug 2008 at 1:41am
Hi,
 
My table name is based on a view - {Communications.Summary} from which i have created two groups - namely group 1 "manager" and group 2 "Company id" (i have created this group to avoid duplicates ) and then have a subreport to show communications which has group 1 "date" and group 2 "Communication id"
 
I created a Parameter on the main report and called it SortField and input 1 into Min and Max. 
I then created the formula called "Sort F" which is based on this parameter as above - i have entered the table names here:
 
If  {parameter.?SortField} = "T" Then {table.Comp_Revenue}
Else
     If {?SortField} = "R" Then  {table.comp_Campaign}
     Else
          {table.Comp_Name}
i Placed this formula into report header and used record Sort expert -"A"  however my report still does noes not sort it based on T or R as within the Record Sort expert i have the two groups before my formula!
 
Please could you help further? If i take the company id group out then i get duplicate companies on my report.
 
Thanks in advance
Confused
 
 
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 12 Aug 2008 at 11:53am

Try this instead:

if IsNull({?SortField}) then {table.Comp_Name}
else
Switch(
{?SortField} = "T", {table.Comp_Revenue},
{?SortField} = "R", {table.Comp_Campaigh},
true, {table.Comp_Name})
 
Again, if Comp_Revenue is a numeric field, you MUST convert it to a string as I outlined above in order for this to work.
 
-Dell
IP IP Logged
twinkle
Newbie
Newbie
Avatar

Joined: 16 Jun 2008
Location: United Kingdom
Online Status: Offline
Posts: 32
Quote twinkle Replybullet Posted: 15 Aug 2008 at 2:24am
Hi
 
for some reason it does not sort the whole report..
It initially sorts by my groups and then by revenue...
my revenue filed is a String so the above formatting didnt make a difference 
 
Any thoughts?
 


Edited by twinkle - 15 Aug 2008 at 2:32am
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.