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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort groups differently based on field...

Status
Not open for further replies.

Andrew888

Programmer
Oct 4, 2001
8
US
Hopefully someone can help -- this is for Crystal 8.

Rather than explain, I'll give you the following scenario...The report design would look like this:

Group 1:
SandwichName
Details:
IngredientNumber, IngredientName, OrderBy

So...it could look like this when viewed with data:

Group:
ABT Sandwich
Details:
1, Bread, Asc
2, Avocado, Asc
3, Bacon, Asc
4, Tomato, Asc
5, Bread, Asc

Group:
BLT Sandwich
Details:
1, Bread, Asc
2, Bacon, Asc
3, Lettuce, Asc
4, Tomato, Asc
5, Bread, Asc

The detail section shows in order by the IngredientNumber...The third column labeled "OrderBy" would tell you how to sort the column (ASC or DESC). So, if it is 'Asc', then sort IngredientNumber in numerical order (1-5). If the ingredients for one group were labeled for 'Desc', then we'd want the IngredientNumber order to be Descending (5-1).

How can this be done?
 
You need a formula to create an ascending or desc sort value based on the Orderby Field -with a number it's easy -just reverse it with a minus sign,

So is the sequence just a reverse of ItemNumber? Sort by a formula of
if {table.orderby}="Asc" then
{table.itemnumber} else - {table.itemnumber}

but how do you reverse sort a string? It is possible, so let me know if you need that?
 
I needed, if the OrderBy said 'Desc' for the report to sort that group from 5-1...This was solved by creating a new formula that multiplied the IngredientNumber by -1 if the OrderBy said "Desc"...that way, the report good be sorted by the new formula with Ascending turned on...

In the real world (my problem was like the example), I had three fields -- the item order (0 to 5), the item, and a boolean character for normal or reverse order (true = normal, false = reverse). So, when third value was for reverse, having the item order number multiplied by -1 achieved the necessary result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top