Search code examples
crystal-reports

Sort based on specific field within a group


I have a report which I need to Group by type but the rows under the group should be sorted based on specific field code. from the below eg. the Reason field needs to be sorted in the order NSL,RWR,PAL,CON order within the grouping.

TYPE        DATE     NAME        CODE

**CEM**
Cem                              NSL
Cem                              RWR
Cem                              PAL
Cem                              CON

**FUN**
FUN                              NSL
FUN                              RWR
FUN                              PAL

 **IP**
IP                               NSL
IP                               RWR
IP                               PAL

Solution

  • The easiest way to do this is to create a formula "Priority" like this:

    if CODE="NSL" then 1 else 
    (if CODE="RWR" then 2 else 
    (if CODE="PAL" then 3 else 
    (if CODE="CON" then 4 else 0)) )
    

    and put in into the detail row of you report. Then goto "Report" menù ->"Record Sort Expert" and sort the detail with your formula "Priority"