Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Using 2 date ranges to filter different columns. Post Reply Post New Topic
<< Prev Page  of 2
Author Message
vinpa
Newbie
Newbie
Avatar

Joined: 27 Jul 2009
Location: Canada
Online Status: Offline
Posts: 10
Quote vinpa Replybullet Posted: 28 Jul 2009 at 7:07am
Yeah, I was trying to post an image but it seems this tool is non-functional.
IP IP Logged
vinpa
Newbie
Newbie
Avatar

Joined: 27 Jul 2009
Location: Canada
Online Status: Offline
Posts: 10
Quote vinpa Replybullet Posted: 28 Jul 2009 at 7:25am

Product Code   Commodity Code   Part Number   Ship Quan.   TotalSales

                         Assembly                 60                    10                 2207.09
                                                        Previous Year    12                 2410.23
                         
                         Assembly                 61                    20                 7878.09
                                                        Previous Year    5                   2207.23
 
                         Assembly                 62                    10                 2207.09
                                                        Previous Year    12                 2410.23
 
Where previous year (as of right now) is the same value as above it because it's just grabbing the same information, rather than the year before.
 
Hope this gives you a better idea.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Jul 2009 at 7:56am

So your rows data is already summed per part #?

If I am understnading your data and if you want your end report to look like the above...

Change your select statement in teh Select Expert to pull previous years data.

( {SHIPPER.SHIPPED_DATE} in Minimum ({?Shipped Date}) to Maximum ({?Shipped Date}) or
{SHIPPER.SHIPPED_DATE} in (DateAdd("y",-1,Minimum ({?Shipped Date}))) to (DateAdd("y",-1,Maximum ({?Shipped Date}))) ) and
not ({PART.PRODUCT_CODE} in ["Advertising", "Misc", "Packaging", "Repairs"]) and
{CUSTOMER_ORDER.STATUS} = "C" and
{SHIPPER_LINE.USER_SHIPPED_QTY} <> 0.00
 
You may want to group your data (probably on Part #).
You can make a formula field to show either the Part # or the Text "Previous Year" as:
if year({SHIPPER.SHIPPED_DATE})=year(currentdate) then totext({table.partnumber},0,"") else "Previous Year"
IP IP Logged
vinpa
Newbie
Newbie
Avatar

Joined: 27 Jul 2009
Location: Canada
Online Status: Offline
Posts: 10
Quote vinpa Replybullet Posted: 28 Jul 2009 at 8:24am
That is pretty much what I am tring to accomplish.
 
However, I used:
 

if year({SHIPPER.SHIPPED_DATE})=year(currentdate) then totext({SHIPPER_LINE.USER_SHIPPED_QTY},0,"") else "Previous Year"

but this only prints out the same data as current year.
 
Is there a way to subtract 1 year from this SELECT in order to display last year's data?
 
Yes, I used SUM in order to get the total number of a specific parts on the report.  I also used @LINE CDN EQUIVALENT for the prices.
 
I simply need to get the second row to display the data from last year.  This is so CRAZY!  Angry
 
 
Thank you so much, any more help is GREATLY APPRECIATED! : )
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Jul 2009 at 8:35am

OK back to basics here to start.

1. You must first get the report to select the correct data rows either by filtering the data before it gets to crystal (via stored procedures, views, etc) or after it gets to crystal via the Select Expert. This is where I was suggesting to alter your select statement. If that is working properly...
 
Your rows of data are not already summarized as in your sample data. Therefore you will need to create groups to do this.
Group on Part Number
Group on Shipped Date in Descending order and set "for each year"
Now you can get your SUMS at Group LEvel 2 (shipped date) to compare yty per Part #.
You can play around with the formatiing and supressing items as needed.
Is any of this making sense?
IP IP Logged
vinpa
Newbie
Newbie
Avatar

Joined: 27 Jul 2009
Location: Canada
Online Status: Offline
Posts: 10
Quote vinpa Replybullet Posted: 28 Jul 2009 at 9:45am
Okay...
 
So the SELECT Expert is essentially an SQL query that returns the data I wish to use in the report.
 
From there, I can create formula fields to manipulate the returned data in order to place values where I wish.
 
I am a little confused with the grouping and group levels.  Also, why I cannot simply take the value a user enters at the opening prompt, for example, 12/31/2008, subtract 1 from the year value, and return the same data a year earlier.
 
Are the any free instructional tutorials or ebooks you can refer to me?  Again, this seems like such a simple task, perhaps I am not explaining myself well enough.
 
A million thanks and appreciate any additional insight you can give me on this.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 28 Jul 2009 at 10:01am
Originally posted by vinpa

So the SELECT Expert is essentially an SQL query that returns the data I wish to use in the report.
 
Basicaly although it uses Crystal Syntax which is close to SQL. It should be written to return a TRUE or FALSE per row of data that is being called via the DB Expert.
Originally posted by vinpa

From there, I can create formula fields to manipulate the returned data in order to place values where I wish.
 
 
Close, generally your formulas are evaluating a row of data although you can use variables and summaries adn place these on Headers and Footers.
Originally posted by vinpa

I am a little confused with the grouping and group levels. 
 
 
My experiance is this confuses new users the most however it also the crux of good design. It is essential to grasp it how it impacts the row level data.
Originally posted by vinpa

Also, why I cannot simply take the value a user enters at the opening prompt, for example, 12/31/2008, subtract 1 from the year value, and return the same data a year earlier.
 
 
 You can (that is the query I started the thread ansewer with) however you are just getting more rows of data from your source. YOu still have to design the report to compare it.
Originally posted by vinpa

Are the any free instructional tutorials or ebooks you can refer to me? 
 
 
Not that I am aware of. If you have to use crystal for more than this one design buy Brian's book from this site (or get the Ebook and learn on line). It is an excelent resource and you will learn what you need to step by step.
Originally posted by vinpa

Again, this seems like such a simple task, perhaps I am not explaining myself well enough.
 
 
 It can be an easy process but there the questions you are asking go to the base design of the report and it is very hard to do that via posts. IT is much easier to assist in tweaking an already designed report Big%20smile
Originally posted by vinpa

A million thanks and appreciate any additional insight you can give me on this.
Glad to help you enter the world of Crystal
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Jul 2009 at 7:01am
I don't mean to butt in...
 
Crystal is not my first choice for record selection.  If you can write a stored proc, you will find Crystal is much easier to use, as you can your DB to do the heavy lifting of gathering the data that you want to display. 
 
In this case, taking an EndDate, I would create a temp table with the itemnumber, thisYear, lastYear...keeping it simple for the example.
 
I would do something like:
select partNumber, sum(sold) as thisYear, 0 as lastYear  into #compare from tableA group by partNumber where soldDate between datediff(year, -1, @dateEnd) AND @dateEnd
 
Then
Update #compare
set lastYear = ss.sold
from #compare as c
 join (select partNumber, sum(sold) from tableA group by partNumber where soldDate between dateadd(year, -2, @endDate) and dateadd(year, -1, @endDate)) as ss On ss.partNumber = c.partNumber
 
select * from #compare
 
 
What your goal is, for Crystal/any reporting tool, is to get all the data that you need to display in one row of data. 
 
In a stored proc/view, you can easily accomplish this.  Joining straight to tables in Crystal, is possible, but so much more difficult, and it might not be possible as you would want to join on different date ranges.
 
If you are advanced at SQL, leverage that skill and the database software to gather what you need, rather than coercing Crystal to do it.  Let SQL do the data retrieval and Crystal the data display....play to each parts strengths.
 
Hope this helps.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 29 Jul 2009 at 7:02am
As a last note, the only book that I can recommend, in good conscience, is Brian's.  Whenever I have needed something, that is where I have found it.  Other than that, it is pretty hit and miss.
IP IP Logged
<< Prev Page  of 2
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.