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
  1. Select Insert, Parameter Field from the menu bar and click New.
  2. Name the parameter Sort Order; you will use this name in the formula.
  3. 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)
  4. 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
  1. Select Insert, Formula Field from the menu bar and click New.
  2. Name the formula Sort and click OK. You will use this formula when you group the report.
  3. 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

  1. Select Insert, Group from the menu bar.
  2. 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:

  1. 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#
  2. 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