Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Sorting using a parameter Post Reply Post New Topic
Page  of 2 Next >>
Author Message
theotherdodge
Groupie
Groupie


Joined: 17 Nov 2008
Online Status: Offline
Posts: 40
Quote theotherdodge Replybullet Topic: Sorting using a parameter
     Posted: 02 Dec 2009 at 5:56am
Ok, this is another step in a report Im trying to create.  I have got the report done, but now I need to be able to sort the data based on the user's parameter (either 1 for sort by Revenue $ or 2 by Revenue%).
 
I supress the detail and only show the group summary and the report looks like this:
 
Customer Name     Revenues     Costs     Revenue$     Revenue%
Exxon                      123,252      58,989      64,263           52.06%
BP                            500,000     100,000   400,000           80.00%
 
Thanks!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Dec 2009 at 6:08am
create a formula like:
if @param = 1 then
  {table.revenueDollar}
else
  {table.revenuePercent}
 
then set the group on the formula.
 
HTH
IP IP Logged
theotherdodge
Groupie
Groupie


Joined: 17 Nov 2008
Online Status: Offline
Posts: 40
Quote theotherdodge Replybullet Posted: 02 Dec 2009 at 7:07am
"then set the group on the formula."
 
I dont quite follow what you mean....? 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Dec 2009 at 7:08am

I will chime in here because it was not clear in your post that these are summary values on a grouped data level (Customer) which is what you want sorted.

The only way I know to really sort groups dynamically is with the top N function. The problem is that both of your values are not direct values from an insert summaries which is needed for top N.

You will have to play with this but basically Lockwelles approach is the foundation. You need to flip a value in the a formula field (if-then) but then you need to use the Insert Summary function (like a SUM) at the group customer level on that formula and use that for your TOP N sort but set the TOP N to a number higher than the largetst number of customers in your report and it will sort all.


Edited by DBlank - 02 Dec 2009 at 7:10am
IP IP Logged
theotherdodge
Groupie
Groupie


Joined: 17 Nov 2008
Online Status: Offline
Posts: 40
Quote theotherdodge Replybullet Posted: 02 Dec 2009 at 7:20am
DBlank:  yes, they are summary values and I am supressing the detail level.
 
And Im still lost! lol...sorry!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Dec 2009 at 7:35am
This one is tricky but here is the process.
Do each step seperate and test it (run your report) so you see what is happening.
Create a parameter ... (1 for sort by Revenue $ or 2 by Revenue%)
Now create a formula field. This part is where you will have to figure out what values to put in later. For testing/learning though just use it to flip between two easy report values...
Call the formula "Sort"...
if @param = 1 then
  {table.revenueField}
else
  {table.CostField}
Place this on your report details (you need to unsupress these for now)
Now use the insert summary function (Sigma Sign) and select the @Sort formula field as a SUM with a summary location on Group footer 1 (customer name).
Run your report with each param value. See how it changes your numbers and your sum.
Suppress youre details again if you do not need them anymore.
Now go into the group sort expert
Select for this Group sort=Top N
based on = SUM of @Sort
Where N is = 1000 ( or any number larger than your total number of customers in the DB)
hit OK.
 
Now instead of sorting the customers (groups)by alpha customer name it is sorting by the Sum of thje Sort formula for each customer.
Now the trick is to figure out which value to use the "Sort" formula.
It cannot be the other values I gave you in the other post as these use multiple Summary function in them.
Test this out and see what you can come up with.
 


Edited by DBlank - 02 Dec 2009 at 7:37am
IP IP Logged
theotherdodge
Groupie
Groupie


Joined: 17 Nov 2008
Online Status: Offline
Posts: 40
Quote theotherdodge Replybullet Posted: 02 Dec 2009 at 8:22am
I created the parameter and created the formula field and put that formula field on the detail of the report (now unsupressed) but it does not show up in the field list when creating a new summary....
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Dec 2009 at 8:46am
In the "Sort" formula did you use the general DB fields (Cost and Revenue) or did you try and use your formula fields (@Revenue$ and @Revenue%) ?
If you used the @Revenue$ or @Revenue% field the @Sort willnot appear because you cannot summarize a summary.
I realize that this is what you want but you cannot do it.
I wanted you to first get proof of concept and see how it works.
Once you get it to work you only need to figure out what values to use in @Sort that will give you the same sort order (even if it is not the same values).
 
Maybe there are none and this will not work, although hopefully you can learn a new trick, but this is the only way I know of to dynamically sort groups.


Edited by DBlank - 02 Dec 2009 at 8:50am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Dec 2009 at 8:54am
Here is an example of what I mean by using different formulas to achieve the same number. One can be summarized and one cannot
 
YOu have credit and debit fields,
your current summary display is: SUM(creditfield)-SUM(debitField)
This cannot be summarized because it already uses the SUM summary in it.
Here is another way assumin that each data row has either a credit or a debit.
if isnull(Credit) then debit * -1 else credit
Thsi give you one field with positive and negative values in it.
It can be Summed and give you the same value as above so it can be used in your @Sort formula.
The one I am less sure about is the percentage value...
Is this making any sense?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Dec 2009 at 8:57am
OK, let's see if I can clear up my post.  I would create a formula.  Since you are using summary values, hopefully they are 'simple', by which I mean that they are derived using the common aggregates like SUM() and COUNT().
 
If they are common aggregates, you can create a formula like:
if @param = 1 then //just for instance
  SUM({table.revenue}, customer group);  //for sorting by revenue
else
  SUM({table.revenue}, customer group) / SUM({table.revenue}) //percentage of a customer vs the entire report
 
 
if you want, you can drop the formula on the gf line and see if reports the correct number (this just tests that the formula is working as desired). I am assuming that there is a grouping on the customer, otherwise this may need refinement.
 
Now since you want to sort all of your group based on the formula, create a group that will be 'above' the customer grouping.  Instead of selecting a table field to group on, select the formula that you just created...The report will now sort based on the parameter.
 
HTH
 


Edited by lockwelle - 02 Dec 2009 at 8:58am
IP IP Logged
Page  of 2 Next >>
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum