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

A COUNT in Descending Order???

Status
Not open for further replies.

BradB

MIS
Jun 21, 2001
237
US
Is there a way to have a COUNT in Descending order?

I have a running total in the Details section that I want in reverse order. Is this possible?

Example:
Details Section
Original
Count
1
2
3
4

Goal
Details Section
New: Descending
Count
4
3
2
1




 
make the number you are counting negative

Jim Broadbent
 
Take the 2 formula approach, and don't use a running total:

In the report header:
numbervar MyNum := Count ({table.field})+1;

In the details section:
numbervar MyNum := MyNum-1;
MyNum

-k
 
SynapseVampire--

I suppose your solution might seem simple to people who understand variables, but not being one of them (or at least only slowly learning), I thought it was very cool. But--I think you forgot the "whileprintingrecords;" at the beginning of the details formula, no?

-LB
 
Since you have a running total you could also add a regular grand total (Count) and then write a formula that will subtract the RT from the regular total to get your reverse count. Probably have to add 1 to the result to make it work.

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
 
SynapseVampire--

I used the formula's you suggested, but they still don't return a reverse count.

Original
1
2
3
4

Now
-1
-2
-3
-4

Is there something else I should know?

Formulas
Report Header
numbervar MyNum :=Count({@Flag})+1;

Details
WhilePrintingRecords;
numbervar MyNum := MyNum-1;
MyNum


 
I created a formula that multiplies the running total by -1, and while it returns a negative, it still doesn't reverse the count.
 
Brad,

You need to choose something besides your formula to count. Pick any field from the database that you are displaying..

Lisa

 
Okay...I sort of figured out why the formula wasn't working. I'm HIDING the detail, and when I double click on the group to open the detail, it fails to calculate in reverse order. If I show ONLY the details section and hide the groups, the formula works. When I drill down from the groups, it doesn't. What gives?
 
No idea what's in @flag, and this was the first mention of any groups being used, you'd want something like:

Is the count supposed to be for each group, or for the whole report?

If for the group, use this in the group header, not the report header:

Formulas
Group Header
numbervar MyNum :=Count({@Flag},{table.group})+1;

If this doesn't resolve, please supply a more detailed description of the report.

-k
 
Moving the first formula from the report header to the group header worked.

{@Flag} is either a zero or one based on a criteria I setup. I originally created the running total because I need the count to reset when the @flag=0. Currently, that part doesn't work since I had to get rid of the running total. As it is now, I get the total to count down in reverse, but it's not resetting.

Goal:
@Flag Count(Reverse Count)
0 2
0 1
1 4
0 3
0 2
0 1
1 2
0 1

Any ideas?

Thanks!


 
Now I'm really confused...

So what is the criteria for resetting the count, @flag = 0?

You state that moving it to the group header worked, what isn't working?

This seems like it's doing what you had asked for, but your requirements get fleshed out a bit more with each posting.

Please share what you have in your formulas, the text descriptions are helpful, but I need to know what you're doing.

And why do you care what's in @flag?

-k
 
The Reverse Count DOES work. It just doesn't work exactly as I would like. I need the count to reset when @Flag = 1.

{@Flag} = 1 or 0

Pseudo Code
If {@Flag} = 1 then reset the reverse count Else Count.

Group Header
numbervar MyNum;
MyNum:= Count ({TSTrack.DateOfSAL})+1;

Details
WhilePrintingRecords;
NumberVar MyNum;
MyNum:= MyNum-1;

Goal:
@Flag Goal(Reverse Count) As it is now(Reverse Count)
0 2 8
0 1 7
1 4 6
0 3 5
0 2 4
0 1 3
1 2 2
0 1 1
 
You will have to have a group. then you could use :

MyNum:= Count ({TSTrack.DateOfSAL}, {groupname})+1;

Don't know what to group by without more data examples.

Reebo
Scotland (Sunny with a Smile)
 
OK, so you don't want the count per group, it's all based on the nebulous @flag, please share the formula for @flag, since that is the key to everything.

-k

 
Here's the nebulous Flag formula. :)

{@FLAG}
If {TSTrack.DaysOff}=false and {PTD.NonWorkDay}=false
and (DayOfWeek({TSTrack.DateOfSAL}) in 2 to 6)
then 1 else 0

DaysOff is a database field. Did they work that day? It's either True or False

NonWorkDay is a database field that keeps track of holidays, weekends, snow days, etc...It's also either True or False.

DateOfSAL is a database field that is the Day of the timesheet. Date Value.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top