0 like 0 dislike
1 view
asked in Computer Science by (474k points)
How can you apply a sort order to the report?

1 Answer

0 like 0 dislike
answered by (474k points)
Using parameters in Crystal Reports for Blackbaud allows you to easily change a report's sort order without changing the report design. Parameters allow you to change the report to meet your needs. For example, at times, you want to sort the report by Constituent Name, but at other times you may want to sort by State. You can use parameters to "tell" the report which sort order you prefer. Follow these basic steps:

Create the Parameter

Select Insert, Parameter Field from the menu bar and click New.

Name the parameter Sort Order; you will use this name in the formula.

Enter the following prompting text, which the user will see when he or she runs the report: Sort Order? Name (N) State (S) Code (C)

In the Value Type field, enter String as the answer value type the user will enter. You may also enter a default value. Click OK.

Edit Parameter Field

Create the Formula

Select Insert, Formula Field from the menu bar and click New.

Name the formula Sort and click OK. You will use this formula when you group the report.

In the Formula Text box, create the following formula, which calculates the sort order based on the user's answer. Click Accept.

if Not IsNull({?Sort Order}) then

if UpperCase ({?Sort Order}) = "S" then {Constituent.State - Primary} else

if UpperCase ({?Sort Order}) = "C" then {Constituency.Code Description} else

if UpperCase ({?Sort Order}) = "N" then {Constituent.Sort Key} else {Constituent.Sort Key}

This formula will instruct Crystal Reports to calculate the uppercase format of the response and create a final result. If the user leaves the prompt blank, it will use the Sort Key as the final result.

 Insert the Group

Select Insert, Group from the menu bar.

Select the formula that you just created: @Sort. Then select the order you prefer and click OK.

Insert Group

When you preview the report, you will be prompted to select a sort order. In the following example, Crystal Reports will calculate the result of Constituent.State - Primary and group on that field.

Parameter Values

In order to have the choice of Sort Order (Ascending/Descending) simply create two reports. One with the Group in Ascending order and the other with Descending order.

If sorting by multiple data types (ex: String, Number, Date etc) a separate group and formula will need to be created. Examples of sorting by a Number and a Date field in Descending order:

Create two new formulas (Insert, Field Object, Formulas, New)

Name: GroupSortTarget

Formula: if {?Sort Field} = "Number" then {NUMBERFIELDNAME.EN_US} else 0

Name: GroupSortDate

Formula: if {?Sort Field} = "Date" then {DATEFIELDNAME.EN_US} else #1/1/1111#

Create two new groups (Insert, Groups)

Group 2 - Select Group Sort Target, Descending Order

Group 3 - Select Group Sort Date, Descending Order, This section will be printed=for each day
Welcome to Free Homework Help, where you can ask questions and receive answers from other members of the community. Anybody can ask a question. Anybody can answer. The best answers are voted up and rise to the top. Join them; it only takes a minute:

10.2k questions

9.2k answers


3.2k users


Free Hit Counters