You are getting the error because you are trying to return 2 different field types. Logically based on your criteria this would not happen but crystal still enforces the rule of not mixing a string with a number into the same result field.
If {?SortBy} = "Customer" Then {customer.FullName}
else totext({vw_CustomerSales.TotalSales})
will resolve the error but may cause you another one as sorting alpha on a numeric string can get a bit odd unless you pad the left with zeros to make a consistent string length. It also does not resolve your ascending/descending issue.
Here is another approach.
Create two formulas as
SortName
If {?SortBy} = "Customer" Then {customer.FullName}
else 'A'
SortSales
If {?SortBy} = "Sales" then {vw_CustomerSales.TotalSales} else 0
Now do a primary sort on @sortname ascending and a secondary sort on @SortSales as descending.
I am not at a machine to test this out but logically I think it will work.
Edited by DBlank - 08 May 2010 at 5:23pm