Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Creating sum of database field for each day Post Reply Post New Topic
Author Message
Jasmin01
Newbie
Newbie
Avatar

Joined: 14 Nov 2011
Online Status: Offline
Posts: 4
Quote Jasmin01 Replybullet Topic: Creating sum of database field for each day
     Posted: 14 Nov 2011 at 9:38pm
Hi.

I am new to Crystal Reports. I need to create a report that will look similar to this:

               Mon    Tues   Wed   Thur   Fri   Sat
Activities      1242    321   333   5453   653   2121

Where the activites are fields in a database. All of the activities done on the Monday need to be added up to give me the total of 1242, and so on for Tues, Wed, etc.

The user enters in the start date, which will always start on Monday, and the end date will then be Sunday.

I am using the following:

if DayofWeek({@Weekstart}) = 2 then
Sum({Table.Activity})
else 0

Where weekstart is the Monday that the user selected. Now, even when I put in the formula for Tuesday:

if DayofWeek(Dateadd("d",1,{@Weekstart})) = 3 then
Sum({Table.Activity})
else 0

I get the same result. What can i do to get the correct vlues for all the days?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Nov 2011 at 3:42am
your formula is only telling it to sum all of the records (then SUM(field))
IMO I would use a crosstab. It is easier but you could also use Runnning totals, 7 formula fields or vairable formuals.
The crosstab would be
column data use the datefield and set the grouping to 'for each day'
summarized field use table.activity set to a SUM.
play with the formating to make it what you want.
You can alter the day headers to use the weekdayname instead of the date.
 
IP IP Logged
Jasmin01
Newbie
Newbie
Avatar

Joined: 14 Nov 2011
Online Status: Offline
Posts: 4
Quote Jasmin01 Replybullet Posted: 16 Nov 2011 at 8:20pm
I cant use a crosstab, because I need to add several rows after activity, I am looking for lots of information here. Already tried a crosstab, but it did not work.

any other suggestion on how to do this? Without using a crosstab?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 17 Nov 2011 at 3:30am
if this has to be in a header you can use something close to what you were doing (although I don't know what your @weekstart formula is). The formula would insert the activity value or a or zero based on the weekday and then you sum each of the formulas
//Monday
if DayofWeek({@Weekstart}) = 2 then {Table.Activity} else 0
 
//Sum of Monday
SUM({@Monday})
 
 
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