Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Crosstab year to year comparison Post Reply Post New Topic
Author Message
bazinj
Newbie
Newbie


Joined: 23 Feb 2009
Location: United States
Online Status: Offline
Posts: 3
Quote bazinj Replybullet Topic: Crosstab year to year comparison
     Posted: 23 Feb 2009 at 6:58am
Hi All,
I need a crosstab that compares a total count of transactions on one day of the year to same day of the next year.  Looks something like this.
           2008      2009
Jan. 1      55        56
Jan. 2      44        67
Jan. 3      53        66
...
 
The user will enter 2 date ranges for year 1 and year 2
I think I need 2 references to the same transaction table in the database expert and some formula fields.
 
Please provide the steps to do this if possible
thanks  Smile
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Feb 2009 at 11:48am
You should not need any formulas unless you want them for data selection.
Create a crosstab in your Report Header.
In the Cross Tab Expert:
Add your Date field to Columns
Click on Group Options and change to "for each year"
Add the date field to the Rows
click on group options and verify or change to "for each day"
add the field to summarize (transactions I believe) and click on change summary and set the calculate as either SUM or COUNT or DISTINCTCOUNT depending on what you are looking for here.
If you don't want the grand total as a column click on the Customize Style tab and select "Suppress Row grand Totals" and "Suppress Column Grand Totals".
Note this will only return values for each day where some data exists in your table and will not insert zeros if both years had nothing for that day.
OK that was wrong, sorry, been on vacation and need to get back in the swing of things Ouch
 
You do need formulas...
Create a formula for your year data as 'Year' using this
totext(datepart("yyyy",{table.datefield}),0,'')
Create a formula for your day data as 'Day' using this
MonthName(Month({table.datefield})) + ' ' + totext(datepart("d",{table.datefield}),0,'')
Now create the crosstab
 
In the Cross Tab Expert:
Add your @Year formula field to Columns
Add the @Day formula field to the Rows
add the field to summarize (transactions I believe) and click on change summary and set the calculate as either SUM or COUNT or DISTINCTCOUNT depending on what you are looking for here.
If you don't want the grand total as a column click on the Customize Style tab and select "Suppress Row grand Totals" and "Suppress Column Grand Totals".
Note this will only return values for each day where some data exists in your table and will not insert zeros if both years had nothing for that day.


Edited by DBlank - 23 Feb 2009 at 12:02pm
IP IP Logged
bazinj
Newbie
Newbie


Joined: 23 Feb 2009
Location: United States
Online Status: Offline
Posts: 3
Quote bazinj Replybullet Posted: 23 Feb 2009 at 12:06pm
Thanks for the help.  This is getting me closer but here is the output:
                    2008      2009
1/1/2008      55           0
1/2/2008      44           0
1/3/2008       56          0
...
The trick is to show the row as a 'generic' month and day rather than a specific date like 1/1/2008 if that makes sense.
 
I want it to look like this
           2008     2009
1/1      55        56
1/2      44        67
1/3      53        66
 
thanks
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Feb 2009 at 12:16pm
Did you see the repost/edit I did using formulas or did you use my screwed up original post?
The formulas should address the date issues that you described and why I fixed my original post.
Hope it helps.


Edited by DBlank - 23 Feb 2009 at 12:33pm
IP IP Logged
bazinj
Newbie
Newbie


Joined: 23 Feb 2009
Location: United States
Online Status: Offline
Posts: 3
Quote bazinj Replybullet Posted: 24 Feb 2009 at 7:34am
This works.  thanks very much!
Can I ask a related question?
The user wants to compare the first day of the 2008 semester to the first day of the 2009 semester.  These are different calendar days.
spring 2008 semester starts  1/21/2008 and spring 2009 starts 1/19/2009
The will enter 2 different date ranges for comparison and want a report that looks like this
           2008     2009
Day1      55        56
Day2      44        67
Day3      53        66
 
Is this possible and if so ..how is it done?
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Feb 2009 at 8:09am
you could create formla field that would convert the dates to matching "day1", "day2" etc. then use that formula field to insert into your crosstab.
Figuring out your formula may be a little tricky...
Since I can't see what data you have to work with this is harder to figure out.
If you have a field that in the table that indicates the semester you could use that as a starting point. From there maybe use a datediff to subtract a standardized number from the date convert that to the day number and add text to the front of it.
Something like:
"Day " + if table.semesterfield=semester 1 then totext(datepart("y",datediff("d",table.datefield,21)),0,'') else totext(datepart("y",datediff("d",table.datefield,19)),0,'')
You may have to play with this formula to make it work but Ihope it is helpful.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Feb 2009 at 8:11am
Note that the above assumes that the days will always match based on a subtraction process, not sure how floating holidays would impact it.
Another approach might be to just use a running number to do a comparison assuming that there are the same number of days in each semester...
Just a thought.
IP IP Logged
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