Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditional sort 1

Status
Not open for further replies.

yisrael

IS-IT--Management
Feb 11, 2003
28
0
0
US
Is there any way on Crystal Reports to set up a conditional sort?

e.g. if <field1> = TRUE then sort by <field A> but if <field1> = FALSE then sort by <field B>.
 
Sure, and that's very close to it:

Generally this is done by using a parameter (not a field) to allow for changing the column to be sorted, as sortation wouldn't be determined AFTER you have read a field that should have already been sorted.

If {?MySortParm} = 1 then
{table.field1}
else
If {?MySortParm} = 2 then
{table.field2}
else
{table.field3}

Now select this field under the Report->Record Sort Expert.

Your menu options may be different as you didn't state your Crystal version, a basic that should accompany every post.

-k
 
I guess I didn't make myself clear. I am using CR verion 10 developer edition. The datasource is an export from another database dumped into an access mdb. The sort I am loking to do is the following: This info is coming from our donor database. We have individual donors and Organization contacts as donors. The field I am looking at is key indicator - I for individual and O for organization. I want the following order:

If key indicator (for this record) = I then sort by "Individual Last Name" else if key indicator = O the sort by "Organization contact Last Name".

Any ideas?
 
Hi,
If each record indicates what type it is ( I or O ) then
how can you sort 1 record? You could Group by that key field, however, then sort the details...
Perhaps you could give us a sample output of what you want it to look like.

Are there multiple linked tables involved?






[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
I guess it is still unclear. I am only working off of 1 table. The report is grouped allready by another field. Here is what I am doing allready:

Name & Address info
----------------------
<If Key indicator = "I" then place the field "Individual Last Name"> (section a)
<If Key indicator = "O" then place the field "Organization Contact Last Name"> (section b)
Address 1
Address 2
City, State Zip

I have suppressed the blank sections to allow the user to see only the organization contact or the individual name without the spaces. The issue is that the sort key on the database is sorting by name of individual and the name of the Organization. For Example, Merril Lynch with a contact name of Joe American is being sorted as M for Merril Lynch. The users want the sort to be defined as the name of the Organization contact i.e. A for American of Joe American.

My thought would be a conditional sort - i.e. if the key indicator is O sort by org contact last name and if the key indicator is I then sort by individual last name.

Sorry for the wordiness. Thanks for all of your help.
 
So right now you have a formula in detail_a like:

if {table.keyindicator} = "I" then {table.indlastname}

And in detail_b you have a formula like:

if {table.keyindicator} = "O" then {table.orglastname}

And you are suppressing detail_a with a formula:

{table.keyindicator} <> "I"

And suppressing detail_b with :

{table.keyindicator} <> "O"

You should be able to create the following formula:

if {table.keyindicator} = "I" then {table.indlastname} else{table.orglastname}

... as your sort field.

You haven't specified what your group field is, but if you have a group on {table.organization}, then your sort formula will only work within each group. If you want the report to ignore the organization for sorting, you will have to remove the group, and instead, group or sort on the sort formula above.

-LB
 
As you're discovering, trying to describe data makes less sense than supplying examples, in general supply:

Crystal verison
Database/connectivity used
Example data
Expected output

Statements like "The report is grouped allready by another field." aren't helpful, state the field.

Note that my example describes "My thought would be a conditional sort - i.e. if the key indicator is O sort by org contact last name and if the key indicator is I then sort by individual last name."

I'll assume by what you state as a key indicator you mean a field in the table, so use an if based on that field.

Seems an clumsy way to define it if each field is repeating the same thing, so perhaps you have more to divulge, if so, I suggest following my suggestion.

-k
 
Thank you for all of your help. I was able to solve my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top