Solved

Crystal Syntax for finding Last Week's (Mon-Sun) data

Posted on 2009-05-06
6
695 Views
Last Modified: 2013-11-15
Hi,

I'm trying to figure out the Crystal Syntax to bring back all data for last week (Mon - Sun) no matter what the current day is, and without using parameter fields.

Thank you in advance,

Parachute  

// This is the code I currently use with date parameters, but I want to do away the paramter field
// so I can schedule the report to run any day of the week and still bring back data from last 
// Mon-Sun
 
(({Ticket.OpenDate} in datetime({?BeginDate}) to datetime({?EndDate})+1)
or 
({@ResolveDate} in datetime({?BeginDate}) to datetime({?EndDate})+1)
or
({@ResolveDate} > datetime({?Begindate}) and {Ticket.OpenDate} < datetime({?EndDate})+1))

Open in new window

0
Comment
Question by:parachute_505
  • 3
  • 3
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 24316243
Crystal has a LastFullWeek range function.  Unfortunately it returns Sun thru Sat

Try it this way

{Ticket.OpenDate}-1 in LastFullWeek

If you need the other date checks
(({Ticket.OpenDate} - 1 in LastFullWeek)
or
({@ResolveDate} in LastFullWeek)
or
({@ResolveDate} > Minimum(LastFullWeek) and {Ticket.OpenDate} < Maximum(LastFullWeek)+1))

mlmcc
 
0
 

Author Comment

by:parachute_505
ID: 24316915
mlmcc,

Thank you for the quick response.  I am new to using Crystal Syntax, could you explain the need to have "Maximum(LastFullWeek)+1)?  Why does the "+1" need to be there if maximum(LastFullWeek) alread refers to Sunday?

Thanks again

Parachute
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24317289
Maximum(LastFullWeek) is last Saturday.  SInce you want through sunday you have to add 1 day (actually 2 to get to Monday).

mlmcc
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:parachute_505
ID: 24317467
Perhaps I'm misunderstanding the LastFullWeek function.  My understanding is that the LasFullWeek() is Sunday-Saturday.  So I thought maybe if I wrote --> {Ticket.OpenDate} in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)) that I would get Monday-Sunday

====================================================
This is what I came up with, but it is returning Monday-Saturday
====================================================
(({Ticket.OpenDate} in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)))
or
({@ResolveDate} in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)))
or
({@ResolveDate} > dateadd("d",1,minimum(LastFullWeek)) and {Ticket.OpenDate} < dateadd("d",1,maximum(LastFullWeek))))

====================================================
I need Monday-Sunday so I added "+1"
====================================================
(({Ticket.OpenDate} in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)+1))
or
({@ResolveDate} in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)+1))
or
({@ResolveDate} > dateadd("d",1,minimum(LastFullWeek)) and {Ticket.OpenDate} < dateadd("d",1,maximum(LastFullWeek)+1)))
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 24317970
The problem is probably you have a DATE-Time field and the time on the LastFullWeek will be 00:00

You could use
dateadd("d",2,maximum(LastFullWeek)



(Date(({Ticket.OpenDate}) in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)))
or
(Date({@ResolveDate}) in dateadd("d",1,minimum(LastFullWeek)) to dateadd("d",1,maximum(LastFullWeek)))
or
(Date({@ResolveDate}) > dateadd("d",1,minimum(LastFullWeek)) and {Ticket.OpenDate} < dateadd("d",1,maximum(LastFullWeek))))


mlmcc
0
 

Author Comment

by:parachute_505
ID: 24319986
mlmcc,

Thanks again for your help.  I was able to use the syntac below and have it work 99.9% successfully.  The other 0.1% I used your suggestion on a field that uses the SUM function --- CDate(dateadd("d",2,maximum(LastFullWeek))) --- or ---  CDate(dateadd("d",1,maximum(LastFullWeek)+1))

// Syntax to return data for Previous Week (Mon-Sun) without using data parameter fields
(({Ticket.OpenDate} in CDate(dateadd("d",1,minimum(LastFullWeek))) to CDate(dateadd("d",1,maximum(LastFullWeek))))
or
({@ResolveDate} in CDate(dateadd("d",1,minimum(LastFullWeek))) to CDate(dateadd("d",1,maximum(LastFullWeek))))
or
({@ResolveDate} > CDate(dateadd("d",1,minimum(LastFullWeek))) and {Ticket.OpenDate} < CDate(dateadd("d",1,maximum(LastFullWeek)))))
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1. Set up your parameter at the report level as usual, check the box Multi-value, and set the Data Type to String 2. Set the Stored Procedure Parameter to varchar(max)  --<---- This part here is the key to it's success Example:    @cst_key var…
Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now