Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Problem with date order when using ToText Post Reply Post New Topic
Author Message
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Topic: Problem with date order when using ToText
     Posted: 24 Oct 2013 at 12:59am

Hi,
 

I have created a custom sort field to my report as shown below. 
The idea is if sort string is null I want to sort by work date and time card index else I want to sort by work date and sort string

If IsNull ({ListofProfDetailTime.PresTimekeeper1__TkprDate__Title1__SortString}) then
    toText({ListofProfDetailTime.WorkDate}) & ToText({ListofProfDetailTime.Timecard1__OrigTimeIndex})
else
    toText({ListofProfDetailTime.WorkDate}) & ToText({ListofProfDetailTime.SortString})

 

However when the report is displaying the order of the work date is wrong
 

The work date is coming out something like :
 

07/10/2013

08/09/2013

09/10/2013

10/10/2013

22/09/2013

Month 09 is after 10. 

Can someone please help me to solve this.

IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 24 Oct 2013 at 2:00am
Hi
 
Since you have converted date to text, it is sorting based on text (ASCII) values.
 
Do the following
 
--Place the below formula in your report as it is.
--Go in Report Menu--Record Sort Expert and Add only '({ListofProfDetailTime.WorkDate}) ' to it and sort by Ascending / descending.
 
So, it will sort your records based on your date not on your formula
 
 
Thanks,
Sastry
IP IP Logged
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Posted: 24 Oct 2013 at 3:02am
Thank you Sastry.  This works.  but I am confuse now.  Does that mean the sort order is ignoring my formula.  Because I need the sort order by both work date and timeIndex if sort string is null or sort by both work date and sort string if there is a sort string ?
IP IP Logged
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Posted: 24 Oct 2013 at 3:25am
Hi unfortunately this is not working what Sastry has suggested.  Does anyone have any other ideas please ?
IP IP Logged
charlese
Newbie
Newbie


Joined: 21 Apr 2011
Online Status: Offline
Posts: 33
Quote charlese Replybullet Posted: 24 Oct 2013 at 3:26am
By adding the work date in the record sort expert it is ignoring my formula totally and just sorting it by work date.  Whereas I need to sort the report by both work date + timeIndex or Work Date + Sort string.
IP IP Logged
Sastry
Moderator
Moderator
Avatar

Joined: 16 Jul 2012
Online Status: Offline
Posts: 537
Quote Sastry Replybullet Posted: 24 Oct 2013 at 3:27am
No, it is not ignoring your formula.  Your formula is not in either date format or in string format.  It is both.  So, it is converting formula results into string and based on ASCII value of the string it is sorting.
 
For example :
 
for date 09/10/2013 ASCII value would be (it is example value) 200,515
so,
 
09/10/2013  --200515
10/10/2013 -- 200615
11/10/2013 -- 200715  so, on..
 
Heare the value of date starts from first digit onwards and your sort is based on ASCII value not on real date.
 
 
 
Thanks,
Sastry
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 24 Oct 2013 at 10:33am
you double posted this, and Sastry is basically giving the same solution as me and DBlank. Just a slightly different twist.

as another solution...Sastry's explanation tripped this thought, how about changing your formula to someting like
local numbervar tot
tot := year({table.workdate}) * 100 * 100 * 10;
tot := tot + month({table.workdate}) * 100 * 10;
tot := tot + day({table.workdate}) * 10;
tot := tot + {ListofProfDetailTime.Timecard1__OrigTimeIndex}; //or the other field

tot

then you can sort by the formula as everything will be 1 number.

you would probably want to group by the workdate, and order by the formula...but that might be more work than just having 2 groups.

Grouping on the above formula would be silly
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