1211558 - How to dynamically changing the sort direction of a field on the report in Crystal Reports?

SAP Knowledge Base Article - Public

1211558 - How to dynamically changing the sort direction of a field on the report in Crystal Reports?

Symptom

  • How can you dynamically sort report records in ascending or descending order in Crystal Reports?

Environment

  • Crystal Reports 2008
  • SAP Crystal Reports 2011
  • SAP Crystal Reports 2013

Resolution

  • To dynamically sort a database field in ascending order, or desending order, follow the general steps below:
        
    1. Create a parameter with 2 default values in the picklist: Descending and Ascending.
      • On the 'Insert' menu, click 'Parameter', then click 'New'.
      • Type the name and prompting text for the parameter in the corresponding boxes.
      • In the 'Type' box, click 'String'.
      • Click 'Set Default'.
      • In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.
      • Repeat the above step for 'Ascending'.
      • Click 'OK', then click 'OK' again to return to the report.
            
    2. Create 2 formulas based on the field you want to change the sort direction on:
      • On the 'Insert' menu, click 'Formula', then click 'New'.
      • Create this formula: @Asc
           
            If {?Parameter} = "Ascending" then {DatabaseField}
           
      • Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.
      • Click 'New' and create this formula: @Des
          
           If {?Parameter} = "Descending" then {DatabaseField}
            
      • Save this formula and close the Formula Editor.
      • Click 'Close' to return to the report.
            
    3. Sort the report based on these two formulas.
      • On the 'Report' menu, click 'Sort Records'.
      • In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.
      • Under 'Sort Direction', click 'Ascending'.
      • In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.
      • Under 'Sort Direction', click 'Descending'.
      • Click 'OK' to return to the report.
               
    4. Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.

Keywords

SORTING DYNAMIC ORDER DESCENDING ASCENDING Seagate Crystal Reports Sorting records Using parameters and formulas Crystal Reports 5 or higher , c2006057 , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

Product

Crystal Reports 2008 V0 ; Crystal Reports 2008 V1 ; SAP Crystal Reports 2011 ; SAP Crystal Reports 2013