Print Page | Close Window

Totals of YTD and Monthly in the same report?

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17890
Printed Date: 05 May 2024 at 3:13am


Topic: Totals of YTD and Monthly in the same report?
Posted By: bholt
Subject: Totals of YTD and Monthly in the same report?
Date Posted: 31 Oct 2012 at 10:49am
Ok, so I've been using Crystal Reports for about a week now so I'm very new to it and have only taken the intro. class via Blackbaud (signed up for the intermediate in a week or so).
 
I've got enough knowledge to get a report for my boss going, though, and I've got 95% of it completed. However, I'm stuck on this last bit. I have a summary of the gifts in the report, and that's working fine. I have it filtered so that it only shows the sum of gifts given in this fiscal year, and then I have the per cent of our yearly goal using this formula: sum({GfFnds_1.GfFnds_1_Amount},{GfCnBio.GfCnBio_Constit_Code}) % 525000. And that is also working fine.
 
However, I also need to show the sum of giving for the current month (or whatever month) and the % of the goal we have for that corresponding month. I tried to do the % with the formula nelow, and although I'm told there are no errors the result is 0 which is definitely not correct. So clearly I'm not writing the right formula, but I'm not sure what to do to get the total for the month on the same report as the total for the year to date (and then get the % of that monthly total). Any help? Thanks!!
 
if {Gf.Gf_Date} in DateTime (2012, 10, 01, 00, 00, 00) to DateTime (2012, 10, 31, 00, 00, 00)then sum({GfFnds_1.GfFnds_1_Amount},{GfCnBio.GfCnBio_Constit_Code}) % 37500



Replies:
Posted By: DBlank
Date Posted: 01 Nov 2012 at 3:58am
there ar eseveral ways to approach this but here is one
write a formula to give you the value of the amount when the date is in the current month and zero all other row s out. then sum this at the report footer level
//currentmonthonly
if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount} else 0
 
use this formula in your sum % formula
 
sum(@currentmonthonly) % 37500


Posted By: bholt
Date Posted: 01 Nov 2012 at 9:10am
Hi DBlank,
Thanks so much for your help.
 
I've tried your suggestion and it got me part of the way there...I think I'm formatting it incorrectly. I am unsure as to how to incorporate the monthtodate formula into the sum/% formula? I came up with the formula below, which does give me the % based on the 37500, buuut doesn't seem to filter out gifts that weren't made last month (I did last month since it's Nov. 1st and nothing will have been recorded yet in the current month). What am I missing? :-/ Also, can I use the same //lastmonth only if formula to also create a line that shows the total amount of giving in the last month (or the current month depending on when I run the report)?

Thanks so much for bearing with me!!! I'm trying to get the hang of this!
 
//lastmonthonly if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
sum({GfFnds_1.GfFnds_1_Amount}, {GfCnBio.GfCnBio_Constit_Code}) % 37500


Posted By: bholt
Date Posted: 01 Nov 2012 at 9:41am
Also, if I try to insert the current month only information into the sum formula I get an error message telling me I'm missing a ). But no matter where I add one, I get the same message. I tried it like this:
 
//lastmonthonly if {Gf.Gf_Date} in lastmonthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
sum(@lastmonthonly {GfFnds_1.GfFnds_1_Amount}, {GfCnBio.GfCnBio_Constit_Code}) % 37500
 
And like this:
 
sum(//lastmonthonly if {Gf.Gf_Date} in lastmonthtodate then {GfFnds_1.GfFnds_1_Amount) else 0 {GfFnds_1.GfFnds_1_Amount}, {GfCnBio.GfCnBio_Constit_Code}) % 37500
 
Same error for both


Posted By: DBlank
Date Posted: 01 Nov 2012 at 9:47am

I need a little clarification (but just so you know you cannot put where conditions on summaries the way you are trying to do)

do you need the month to date per constituant or for all constituants together (or both)?
 
either way make one formula field, as the exmple call it currentmonth as
if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
YOu can place this on the detail section to see how it works.
for any row that was in this month you should see the gift amount, for all the other rows not in this month you should see a 0.
now you can sum this new formula field at the group level
sum( mailto:%7b@currentmonth - {@currentmonth }, {GfCnBio.GfCnBio_Constit_Code})
to see the total gifts for the month only.
 
Or you can sum it at the report level to see the month total across all consituants
sum( mailto:%7b@currentmonth - {@currentmonth })
 
If you chaneg these last 2 formulas to include %3700 it will change it from the sum to your percentage display
 
 
 
 
 


Posted By: bholt
Date Posted: 01 Nov 2012 at 10:16am
Ah, I need to see the month to date for all constituents together.
Oooh ok, so I think I understand now. But I'm having 2 issues trying to implement this.
 
First: I made the formula field like you said: //lastmonth if {Gf.Gf_Date} in lastmonth then {GfFnds_1.GfFnds_1_Amount) else 0 and named the formula lastmonth.
 
There aren't any errors in the formula according to CR, and the formula above is exactly what I have in CR. But when I put it into the detail section of my report, nothing shows up in the field - and there should be #s.
 
Second: When I try to make another formula to sum at either the group or report level: sum( mailto:%7b@lastmonth - {@lastmonth }) or sum ( mailto:%7b@lastmonth - {@lastmonth }, {CfCnBio.GfCnBio_Constit_Code}) I get this error code: "This field cannot be summarized."
 
?


Posted By: DBlank
Date Posted: 01 Nov 2012 at 10:20am
the
//lastmonth
part is just a notation to to tell you what to call this formula. you will see it turns the text green in the formula editor because the line starts with the // which indicates a notation, not actual formula code
in the formula editor just use
if {Gf.Gf_Date} in lastmonth then {GfFnds_1.GfFnds_1_Amount) else 0


Posted By: DBlank
Date Posted: 01 Nov 2012 at 10:23am
the reason the other formulas got the error
"This field cannot be summarized."
is because your "currentmonth" formula was broken and it was being interpretted as a text field which cannot be summed.


Posted By: bholt
Date Posted: 01 Nov 2012 at 10:25am
Ok, that's what I thought but when I tried to remove it I got this error message: "A number, currency amount, boolean, date, time, time-date, or string is expected here." and it won't let me save it. So I added the // back in 'cause then I didn't get an error. Obviously that's wrong too though! :-/


Posted By: bholt
Date Posted: 01 Nov 2012 at 10:27am
Is it broken because of the //lastmonth? Or is it something else?


Posted By: DBlank
Date Posted: 01 Nov 2012 at 10:28am
sorry, this got mucked up somewhere along the lines
For thismonths data you use
 
if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
 
for last months data you use
if {Gf.Gf_Date} in lastfullmonth then {GfFnds_1.GfFnds_1_Amount) else 0


Posted By: DBlank
Date Posted: 01 Nov 2012 at 10:29am
if you need it to choose between the two I need to know what condition sets the choice.


Posted By: bholt
Date Posted: 05 Nov 2012 at 6:54am
if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
for last months data you use
if {Gf.Gf_Date} in lastfullmonth then {GfFnds_1.GfFnds_1_Amount) else 0
 
Oookay, thanks for clarifying. That was really helpful. Ok based on the formulas above here is what I came up with, and it seems to be working (in the sense that there are no errors according to CR), however the amount is equal to zero, which is definitely not correct. Any idea why that might happen?
if {Gf.Gf_Date} in lastfullmonth then Sum ({GfFnds_1.GfFnds_1_Amount}) else 0
Then for the % I did:
 
if {Gf.Gf_Date} in lastfullmonth then Sum ({GfFnds_1.GfFnds_1_Amount}) else 0 % 37500


Posted By: DBlank
Date Posted: 05 Nov 2012 at 8:13am
do not use an if-then on a sum.
You cannot conditionally summarize like this. That can be accomplished via Running Totals or shared variables but that is a different approach.
 
Try to reverse your thinking. What ew are doing is converting your row level data to be either the row value or a 0. Now if you sum ALL of these it would be the same total as if you had only summed some of them because you are zeroing out all of the ones you did not want to include.
 
Lets call the first formula "MTD_only"
if {Gf.Gf_Date} in monthtodate then {GfFnds_1.GfFnds_1_Amount) else 0
Place this on your detail section. You will see it 'zero out' all rows that were not part of this month.
now sum this formula field
SUM( mailto:%7b@MTD_only - {@MTD_only })
this will show you the total for the currnt month only
now if you want to see it as a % add that to the summary
SUM( mailto:%7B@MTD_only - {@MTD_only }) % 37500
 
Does that help?


Posted By: bholt
Date Posted: 05 Nov 2012 at 11:15am
Aaaaaaaah! I think I finally get it!
 
Ok. I've got it working now, thank you so much!! Sorry it took a bit for me to grasp what you were saying.
 
Ok. The only other thing I'm unsure about is how do I get the monthly amount and % to be filtered by constituent code? Looks like it's just doing the total, and I need it to be separated out...

Thanks again!


Posted By: DBlank
Date Posted: 05 Nov 2012 at 1:49pm
Just add in the group condition into the sum portion. It is the sum the field you are grouping on. Place it inthe group footer or header.
SUM({@MTD_only},{table.consituentcode}) % 37500


Posted By: bholt
Date Posted: 06 Nov 2012 at 6:40am
You are amazing! Thank you so much!!



Print Page | Close Window