Using a formula as group sort order

Hi All,
I want to sort the group( DATETIME)  into 4  6-hour intervals. how do I do it in group sort?

example first group

April 1 12:00:00 AM to April 1 5:59:59

second interval

April 1 6 :00:00 AM to April 1 11:59:59
third interval
April 1 12:00:00 PM to April 1 5:59:59 PM

fourth interval
April 1 6:00:00 PM to April 1 11:59:59 PM

thanks in advance
maverickxxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kenwagersCommented:
Create a new Formula field as follows (edit as needed for your own text formatting):

Change the {test.TS} to your date field.

totext({test.TS},'yyyy-MM-dd')+' - '+
if Time({test.TS}) > time(00,00,00) and Time({Holder.ts}) < Time(06,00,00)
   then 'Midnight to 6:00 AM'
else if Time({test.TS}) > time(05,59,59) and Time({Holder.ts}) < Time(12,00,00)
   then '6:00 AM to Noon'
else if Time({test.TS}) > time(11,59,59) and Time({Holder.ts}) < Time(18,00,00)
   then 'Noon to 6:00 PM'
else  if Time({test.TS}) > time(15,59,59) and Time({Holder.ts}) <= Time(23,59,59)
   then '6:00 PM to Midnight'

Then, make this new field your group field.
0
mlmccCommented:
TO get them ordered properly you will have to use the specified order option in the sort order dropdown.

You can then specify the order as desired.

mlmcc
0
James0628Commented:
You could also get them sorted by using a small trick.  Add spaces to the front of the values.  Put 3 spaces in front of "Midnight to 6:00 AM", 2 spaces in front of "6:00 AM to Noon", one space in front of the next interval name and no spaces in front of the last one.  If you can live with a little space in front of some of the interval names, it's a lot easier than dealing with "specified order".

 James
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

maverickxxAuthor Commented:
Thanks for  your replies.

 But what if I was passing the range of  dates and wanted to sort them by 6 hou r intervals per day  for  range of dates?
thanks
0
kenwagersCommented:
The function I included above should do that.  Sort or Group by that new function.


totext({test.TS},'yyyy-MM-dd')+' - '+
if Time({test.TS}) > time(00,00,00) and Time({Holder.ts}) < Time(06,00,00)
   then '1 - Midnight to 6:00 AM'
else if Time({test.TS}) > time(05,59,59) and Time({Holder.ts}) < Time(12,00,00)
   then '2 - 6:00 AM to Noon'
else if Time({test.TS}) > time(11,59,59) and Time({Holder.ts}) < Time(18,00,00)
   then '3 - Noon to 6:00 PM'
else  if Time({test.TS}) > time(15,59,59) and Time({Holder.ts}) <= Time(23,59,59)
   then '4 - 6:00 PM to Midnight'

In the above revision, I put numbers in front of the labels so they will sort by that number within the date.
0
maverickxxAuthor Commented:
KenWagers,
 That worked  for me . An another question if I wanted to show  zeros for no data could I do that? right now it is only showing for ones which has data

I need to show all four intervals  irrespective of data

 02-01-2010 '1 - Midnight to 6:00 AM'    0
 02-01-2010   2 - 6:00 AM to Noon     50
 02-01-2010   3 - Noon to 6:00 PM'     62
 02- 01-2010 4 - 6:00 PM to Midnight   0


02-02-2010 '1 - Midnight to 6:00 AM'  20
 02-02-2010   2 - 6:00 AM to Noon    15
 02-02-2010   3 - Noon to 6:00 PM'     52
 02- 02-2010 4 - 6:00 PM to Midnight   15


etc..


0
kenwagersCommented:
You will probably need to generate four calculated fields, one for each time frame.  You can then then create running totals based on that amount, and put labels in the daily group footer that shows the running total value for each of the four time frames.  

For example, the first formula might be:

if Time({test.TS}) > time(00,00,00) and Time({Holder.ts}) < Time(06,00,00)
   then 1 else 0

Create a running total that resets on change in date, and place it in the daily group footer.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maverickxxAuthor Commented:
Kenwagers
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.