Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Conditional Sorting? Post Reply Post New Topic
Author Message
klkemp100
Newbie
Newbie


Joined: 17 Sep 2008
Location: United States
Online Status: Offline
Posts: 5
Quote klkemp100 Replybullet Topic: Conditional Sorting?
     Posted: 07 Dec 2009 at 12:37pm
Using Crystal Reports 10 (though I could use 11).
 
Needing to do conditional sorting based on a passed parameter.
 
for instance, I have a report that has the following columns
 
NAME
DEPARTMENT
JOB TITLE
 
depending on what the user wants <parameter setting>, I want to sort the report by 1 of the 3 columns, sometimes it's NAME, sometimes it's DEPARTMENT, sometimes it's JOB TITLE.
 
thus my question: is there some way within Crystal to do conditional sorting?
 
thanks!
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Dec 2009 at 12:58pm
Yes but if you are grouping that drastically impacts it.
If no grouping just create a formula field called 'Sort'. it will be something like this:
if {?param}=Name then table.namefield else if {?param}='Department' then table.department else table.jobtitle
 
Now in your sort expert just use the {@Sort} formula as your primary sort.


Edited by DBlank - 07 Dec 2009 at 12:59pm
IP IP Logged
klkemp100
Newbie
Newbie


Joined: 17 Sep 2008
Location: United States
Online Status: Offline
Posts: 5
Quote klkemp100 Replybullet Posted: 07 Dec 2009 at 1:04pm

Yes, I am needing to perform the sort at a group level.

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Dec 2009 at 1:12pm

Try and just group on the 'Sort' formula and see if that works for you.

If not, please explain your grouping needs alog with the sorting needs.
IP IP Logged
klkemp100
Newbie
Newbie


Joined: 17 Sep 2008
Location: United States
Online Status: Offline
Posts: 5
Quote klkemp100 Replybullet Posted: 07 Dec 2009 at 1:28pm
Yes the report does have a GROUP, please see the example below
 
Pay_Code      Total Hrs    Wrk Hrs   Non-Wrk Hrs   Prem Hrs

 

ABC REG            X                X

ABC VAC                                                   X

ABC OT               X               X                                       X

ABC TRAIN        X                                    X
 
currently the report is Grouped on PAY_CODE and sorted by PAY_CODE
I would like to have the ability to Sort by 1 of the 4 columns (Total Hrs, Wrk Hrs, Non-Wrk Hrs, Prem Hrs). Basically the user wants to decide how to sort it so that they might have all the paycodes associated with Total Hrs at the top, or maybe paycodes with Non-Wrk Hrs at the top etc.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 07 Dec 2009 at 1:35pm
This appears to be TOP N sorting on group.
This willonly be possible if you can use an Insert Summary function at the group level. YOu cannot do it if you have to write a more complex formula. The premise is the same as I gave you for the other except you need to create a formula that rotates through the 4 fields that you are using to get the differnt totals. and be able to SUM that field at group footer1 (paycode group).
From there you just do a GroupSort on TOP N using the SUM of the 'Sort' formula field and set your top N higher than the total # of paycodes you could have in the report.
Make sense?
IP IP Logged
klkemp100
Newbie
Newbie


Joined: 17 Sep 2008
Location: United States
Online Status: Offline
Posts: 5
Quote klkemp100 Replybullet Posted: 07 Dec 2009 at 1:42pm
ok, thanks!
IP IP Logged
pparukola
Newbie
Newbie
Avatar

Joined: 17 Nov 2009
Location: India
Online Status: Offline
Posts: 8
Quote pparukola Replybullet Posted: 15 Dec 2009 at 5:15am
Hi Guys,
I too have one problem in sorting.

My report structure:

GH1
GH2
GH3
    D1{Sub Report1}
    D2{Sub Report2}
GF3
GF2
GF1

I want to use conditional sort for GH3.

Result will be like this..
One of the subreport2 value will be the GH3 for next group. So I want to sort, such that value coming in Subreport2 should be criteria. Is it possible ??

Kindly advice...

Thanks in advance...
Regards,
Pavan

Try around, things definitely will work.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Dec 2009 at 6:42am
While I am sure that dynamic sorting impacts the report, I use dynamic grouping on several groups to accomplish the complex sorts that my companies uses on it's reports.  I create formulas, and for the most part the ones that work are the ones that take a parameter and then use existing fields in the dataset. 
 
For example, I might have 3 levels of grouping, simply done they would be company, division, customer.....but based on parameters, it might be division, division, customer OR company, company, customer OR customer, company, division OR any other combination of factors.  Why do fields repeat, well, you can't get rid of the group, and the sort applied to the group remains in effect, so the simplest solution is to replace the sort...
 
yes, now that DBlank mentions it, I am sure that there is overhead, but unless I want to build and MAINTAIN 12 reports that basically do the exact same thing except for the sorting it is the price that I am willing to pay.
 
Again, I might have 5 or 6 levels of dynamic grouping to accommodate the variations and twists and turns and subtotals.  I have thought of late, as the company is moving to new reporting tool, to bring out the datasets already presorted/grouped which should speed the report a bit.
 
I am not sure what Pavan is trying to do, but given the current structure of the report, I am not sure that is doable.  If you want to use a value from the subreport to group on, you need to run the subreport prior to the grouping, and then you would need to use shared variables to communicate which value you want to group on, and since it has been moved outside of the group header, it will now return more records that may not be what you want.  Personally, I would try and move the retrieval of the dataset to a stored proc, add all the fields that would be in the subreport and get rid of the subreport, as this will 1 make the report run faster (fewer hits to the db) and allow you to group on a field that you want.
 
HTH
IP IP Logged
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