Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula Question Post Reply Post New Topic
Author Message
mparish
Newbie
Newbie


Joined: 20 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote mparish Replybullet Topic: Formula Question
     Posted: 20 Aug 2008 at 7:36am
How would I create a formula to look at the first six digits of a numeric field disregarding the last two digits yet have all digits show on the report? We have sessions using the date plus two digits; 08200801. I want to pull a report by session yet CR puts it in numeric order so that all sessions for particular day are not in order. Example: 06230805, 06240804, 07180701, 07190502, etc. 
Thanks for your help!!!
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 20 Aug 2008 at 1:56pm
You need to create a formula which parses the text from each of the date related positions in the string and returns the date value. Then you can sort or group on this formula to get the data in the right order. You can put the full field anywhere on the report so that the user still sees the funky field but has no idea that you use a formula behind the scenes for sorting. Here is a sample formula off the top of my head (you might have to debug it if I have a typo):
//Parse two digits at a time and plug into CDate(year, month, day) function
CDate(2000+Val(Mid({table.field}, 5,2)), Val(Mid({table.field},1,2)), Val(Mid({table.field},3,2)))
//
Replace {table.field} with your report field and after you check that I didn't screw up my parentheses, then this should do the trick. 
Also, I have the complete Crystal syntax documented with sample code in three chapters of my Encyclopedia book. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.


Edited by BrianBischof - 20 Aug 2008 at 1:57pm
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
mparish
Newbie
Newbie


Joined: 20 Aug 2008
Location: United States
Online Status: Offline
Posts: 9
Quote mparish Replybullet Posted: 25 Aug 2008 at 2:20pm
That worked!!!! Thank you so much!Clap
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