Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Formula for selecting Weekdays and Weekends Post Reply Post New Topic
Author Message
KennyH
Newbie
Newbie
Avatar

Joined: 01 Aug 2011
Location: United States
Online Status: Offline
Posts: 1
Quote KennyH Replybullet Topic: Formula for selecting Weekdays and Weekends
    Posted: 02 Aug 2011 at 4:52pm
All,
 
I am trying to create a query that returns a results set of weekday transactions only.  I am unsuccessfully using the DayofWeek  function as follows:
//If {Trips.Trip Date} >= Date (2011,07,01) and {Trips.Trip Date} <= Date (2012,06,30)
//and (DayofWeek({Trips.Trip Date},1) = 2
//or   DayofWeek({Trips.Trip Date},1) = 3
//or   DayofWeek({Trips.Trip Date},1) = 4
//or   DayofWeek({Trips.Trip Date},1) = 5
//or   DayofWeek({Trips.Trip Date},1) = 6)
// then
// average {Trips.Passengers})
// else
However, I believe, only the number of weekdays since July 1, 2011 is returned.  My hope is to get the correct syntax to bring back only weekdays of passengers.  Can some one please help?
KwH
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 03 Aug 2011 at 3:24am

Instead of using the "average" function I would do this in three formulas - one to count the number of passengers and another to count the number of week days.  It would look something like this:

{@IsWeekDay}
If DayOfWeek({Trips.Trip Date}, 1) > 1 and DayOfWeek({Trips.Trip Date}, 1) < 7 then 1 else 0
 
if DayOfWeek({Trips.Trip Date}, 1) > 1 and DayOfWeek({Trips.Trip Date}, 1) < 7 then {Trips.Passengers} else 0
 
if sum({@IsWeekDay}) > 0 then
  sum({@WeekDayPassengers})/sum({@IsWeekDay})
 
-Dell
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.