Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Group Sort Formula Post Reply Post New Topic
Author Message
JacobV
Newbie
Newbie


Joined: 09 Jan 2012
Online Status: Offline
Posts: 5
Quote JacobV Replybullet Topic: Group Sort Formula
    Posted: 09 Jan 2012 at 2:08pm
All,

First off - I have to admit that I am very new to Crystal reporting and do not have a strong background in formulas - please have patience :) I am also brand new to the forums - took note of the site from an instructor I took a class on Crystal from a few months back.

I am generating a report and need to sort it by user location.  The problem is, the database stores location in a format such as this:

location 1/building 1/floor 1/room 101
location 2/building 1/floor 1/room 101
etc...

In a standard group sort, I end up with hundreds of groups.  I would like to somehow just group all location 1 information together, all location 2 information together, etc...

Is this possible to do?

If it helps, the portion that I want to group on will always be followed by a "/"

Thanks for the feedback - please let me know if I need to include any additional information.

-Jake
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 10 Jan 2012 at 1:45am

Do you just need the location? if so create a new formula field as follows then group by that;

left({field_name},instr({field_name},"/")-1)
 
it is possible to separate by building, floor and room if required - let me know if you need those too.
 
Regards,
Ryan.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 10 Jan 2012 at 1:55am
You could also use the split function:

split(table.field,'/')[1]

This will get location. For building/floor/room you would change the 1 to a 2/3/4 respectively.
|< /\ '][' ( )
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 10 Jan 2012 at 2:02am
Originally posted by FrnhtGLI

You could also use the split function:

split(table.field,'/')[1]

This will get location. For building/floor/room you would change the 1 to a 2/3/4 respectively.
 
I'd use this ^^
 
Every day is a school day! ;-) All my formula knowledge is pretty much a port from Excel... there is no split or similar in Excel :p
IP IP Logged
JacobV
Newbie
Newbie


Joined: 09 Jan 2012
Online Status: Offline
Posts: 5
Quote JacobV Replybullet Posted: 10 Jan 2012 at 1:33pm
Awesome - just what I needed - worked like a charm.

I encountered a new parameter for the report that I wasn't anticipating that I wonder if you may also have some input on.

I need to break the report down by day of week for one piece (got this) and time of day for another.

For example, looking at a months worth of data I want to determine the volume of data that came in at 7am, 8am, 9am, etc..

My challenge that I am currently stuck on is that the date/time data I have is AM/PM not military. The way I have it setup currently to work means that 7am is no different than 7pm.  I tried Crystal's help and found DTSToTime but this doesn't appear to be a valid function in 2008.

Any thoughts on how to sort this data based on time of day best?

Thanks again for your help - greatly appreciated!
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 11 Jan 2012 at 12:00am
Hi Jacob,
 
I'd do the following, however FrnhtGLI may know of a better way.
 
The following assumes your time field is in the following format "7pm" or "10am" etc - if the string contains minutes/spaces/any other characters the following formula won't work and will need to be revised.
 
numbervar hourampm;
stringvar ampm;
numbervar hour24;
hourampm:= tonumber(left({table.time_field},length({table.time_field})-2));
ampm:= right({table.time_field},2);
hour24:= if hourampm = 12 then 0 else hourampm;
if ampm = "pm"
then
time(hour24+12,0,0)
else
time(hour24,0,0)
 
Replace all the {table.time_field} with your field.
 
Regards,
Ryan.


Edited by rkrowland - 11 Jan 2012 at 12:45am
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.