Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Sorting of column Asc/Desc

Status
Not open for further replies.

rictorsan

Technical User
Sep 6, 2002
25
US
I'm able to 'dynamically' sort a report based on user selection of a column by supplying a parameter, but I can't find a way to expose to the end user the ability to sort on one column either ascending or descending, via a parameter or otherwise. Ultimately I'd like to allow the user to 'click' on a column and have that resort, but I guess this would require customization.

Ideas out there ??

rictorsan
 
If it is a numeric field create a formula of
if {?Sort}="Asc" then {table.number}
else -{table.number}

Then your users can select Asc or not to sort ascendif=ng of descending.

Strings are a bit tricker, but we published a method a few months ago. Check out the back issues of Crystal Clear at Editor and Publisher of Crystal Clear
 
Thanks, that was helpful. However I now have a more difficult scenario. I need to sort by a *formula field*, not a table.column . Unfortunately, this formula exposes a custom UFL function and because I suppose it requires a 2nd pass, is not available for selection via Select, Summation etc. So I used the workaround for manual running totals, which was fine for summation at the group level.

When I create the sort formula you suggested, referencing the new formula used for manual running totals, it is not selectable at Report/Sort. Nor are any other formula that reference any of my UFL functions. Is there a way to expose these 2nd pass formula at Report/Sort ?

rictorsan
 
please post your formula and lets take a look at it. Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
If it is truly a second pass formula then you can't sort on it by definition. The primary question would be - Does it HAVE to be a second pass formula. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
The formula is as follows:

formula= {HLD.quantity} * {@Price} * {hld.unit_size}

@Price = Shared securityArrayHld(5) as double

securityArrayHld(1) = {hld.security_id}
securityArrayHld(2) = {hld.coupon_rate_mtf}
securityArrayHld(3) = CDbl(CStr({hld.issue_date_mtf},"yyyyMMdd"))
securityArrayHld(4) = CDbl(CStr({hld.maturitydatemtf}, "yyyyMMdd"))
securityArrayHld(5) = {hld.gen_price_ptr}

Formula= Price ("Source 1",CurrentDate,securityArrayHld)

(Price is a function that calls the above parameters and is integrated into Crystal via the UFL).

I don't know why it would be in the second pass, unless by design, a UFL call requires a 2nd pass. All I know is the parent formula is unslectable for Report/Sorts, and for selects, and direct group summation (which I got around via manual running totals).

Please let me know if I've left out any info.

Thanks ! rictorsan


 
You might need two formulas. UFL's that do things outside of CR seem to behave better on the printed page if they are WhilePrintingRecords, so have a second variation of the formula WhileReadingRecords and see if you can sort on that.

I'd advise against changing your original formula as that may cause other problems. Editor and Publisher of Crystal Clear
 
I see that you have the word SHARED in the formula, which usually indicates you are working with a subreport. Is that the case? If so, shared variables are always second pass. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
I could not force the formula to evaluate WhileReadingRecords, I get the error 'The formula cannot be used as it must be evaulated later'. So I'm assuming it is a 2nd pass formula, and is therefore NOT availabe for sorting, select statements, charting, ...other areas ?

Ken, I am not working with a subreport. When you say does it HAVE to be a 2nd pass formula..not sure how to get around this. Are you saying perhaps the UFL custom function might be better designed..that there is a way to call it within the 1st pass given the posted formula?
 
So, what does the SHARED signify if you don't have subreports?

Also, I don't think ALL UFLs force you to the second pass, but I suppose it depends on what they do. You appear to have two UFLS in this formula. Could you describe what each does briefly?

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Ok, you helped resolve the issue. The SHARED statement was used to allow re-use of the arrays by formula that require that same array, within the same reports, so that the array would not have to be declared within every formula used by a report. So instead of the entire array, the formula would be preceded only by:

Shared securityArrayHld(5) as double


Once I replaced the SHARED with DIM, all is good. The functions do not require evaluation during the second pass. I'll now have to require that all formula contain the array information directly, instead of enabling reference to the array.

Thanks for your help.

rictorsan
 
Just use "global" instead of "shared".

Global still gives you the ability to retain the value of the variable across formulas; it just doesn't let the value move across the boundaries of main report and subreports (which is the only case requiring the use of "Shared").

Cheers,
- Ido CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top