cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Crystal Reports - Conditional record sorting

Former Member
0 Likes
1,553

I'm attempting to sort report records based on multiple fields, but not as simple as Field A - ascending, Field B - descending, etc. My records have fields "machine", "fault", "magnitude", and "date". Machines are given a fault at a certain magnitude on a certain date. I want to sort based first on "magnitude" (descending) and then "machine"' (ascending), "fault" (ascending), and then "date" (ascending). However, the kicker is that a "machine" may have more than one "fault" and possibly assigned a different "magnitude". I want all "faults" assigned to the same "machine" to be sorted one after the other, even if the "faults" are different "magnitudes"

For example, Machine A has a fault assigned Significant. Machine B has two faults: Severe and Insignificant. Machine C has a fault assigned Severe. Machine D has a fault assigned Insignificant. Machine E has two faults both assigned Significant.

The correct order would be:

Machine B - severe

Machine B - insignificant

Machine C - severe

Machine A - significant

Machine E - significant 1

Machine E - significant 2

Machine D - insignificant

Essentially, I want the records to be supported based on "magnitude" but with "faults" regardless of "magnitudes" for identical "machines" to be kept together.

View Entire Topic
abhilash_kumar
Active Contributor
0 Likes

Ok here's what you need to do:

1. Insert a Group on the Machine field

2. Create a formula called @sort with this code:

SELECT {Fault_field} //replace this with the database field or formula field that displays Fault strings
CASE 'severe' : 1
CASE 'significant' : 2
CASE 'insignificant' : 3
DEFAULT: 4

3. Go to the Insert Summary option > Choose the @sort field to aggregate on and set its aggregation function as "Minimum"

4. Suppress the summary field that CR places on the Group Footer

5. Go to the Group Sort Expert > Select Machine Group as the group to sort ALL and sort it based on the @sort summary field in Ascending order.

-Abhilash