Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Max Value Crazy!!! Post Reply Post New Topic
Author Message
pixelstick
Newbie
Newbie


Joined: 19 Apr 2012
Location: United States
Online Status: Offline
Posts: 1
Quote pixelstick Replybullet Topic: Max Value Crazy!!!
     Posted: 19 Apr 2012 at 10:29am
Anyone know how to duplicate this in Crystal?

SELECT acct, max(mydate) mydate FROM mytable
GROUP BY acct ORDER BY acct

I created a group based on acct, which worked correctly by ordering descending by the mydate field and thus displaying the maximum date value. This works as long as the formula field for mydate only contains the actual database field in it. The apparent problem with this is that I am trying to use a conditional in the formula field to display different text for different dates. Apparently the formula field is evaluated for more than just the last (greatest) field value.

IF {MYTABLE.MYDATE} = #100, 1, 1# THEN
    'Never'
ELSE
    ToText(CDate({MYTABLE.MYDATE}))

This returns 'Never' for every record displayed, when I know for a fact that this is not the case. Any ideas how I can get this to work properly?

Edited by pixelstick - 19 Apr 2012 at 10:32am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Apr 2012 at 4:55am
first, just because it looks odd, I would convert the #100,1,1# to a date...unless your field is a string that looks like that (but then it should have quotes)
 
Just being cautious since it doesn't look the 'norm'
 
As for when the formula is evaluated, depends on where you put it. If you put in a group header/footer, it will only evaluated once per group, but if you place it in the detail section, it will evaluate for every record.
 
ps
 
you should be able to use an aggregate function on the group. I believe that there is a MAX()function which would look like:
MAX({table.field}, {group})


Edited by lockwelle - 20 Apr 2012 at 4:56am
IP IP Logged
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