Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Report group sort order

I'm making a report that will display a list of costumers and some numeric values. I use a formula in order to sort my group, wich is the following :

if {Db.SortOrder} = 0 then
    {Db.CostumerName}
else
     ToText({Db.Value},'00000000',0,'') 

In this way i can group by costumer name or value, the problem is that i need to use a different sorting order for them, ascending order when i group by CostumerName and descending when i group by Value. How can i achieve that ? I've tried the "Sort group by formula" using crAscendingOrder,crDescendingOrder but it said i needed tu use a costant and not a variable (in my case i used db.SortOrder)

like image 712
SilentRage47 Avatar asked Jan 17 '26 23:01

SilentRage47


1 Answers

My approach:

First, create a parameter field ({?Sorted Field}) to choose the sorted field: String; static list that includes 'Customer' and 'Value'; default value is 'Customer'

Next, create a custom function that will convert a string into its ASCII representation, allowing the order to be changed:

// ASCII()
Function (Stringvar characters, Optional Numbervar direction:=crAscendingOrder)

Local numbervar i;
Local stringvar c;

For i:= 1 To Len(characters) Do (
    If direction=crAscendingOrder Then
        c:=c + ToText( Ascw(Mid(characters,i,1)), "#")
    Else
        c:=c + ToText( 256- Ascw(Mid(characters,i,1)), "#")
);

c;

Next, create a formula field that will be used for sorting:

// {@Sorted Field}
Select {?Sorted Field}
Case "Customer": {Db.Customer}
Case "Value": ASCII(ToText({Db.Value},'00000000',0,''), crDescendingOrder)
Default: {Db.Customer}

Finally, reference this field in the record-sort expert:

enter image description here

like image 150
craig Avatar answered Jan 21 '26 09:01

craig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!