Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Period to date and Year to date

I need to get the period to date as well as year to date  charge amounts  by a program.
I am using @ToDate  to retrieve the data from SQL.  I am not quite sure how my formulas should look. I created this formula for the period charges but it just brings back zeros
if date(Minimum ({TPr_ProcedureReimbursement;1.DateTrans},{@Group Program} )) in Cdate({?From Date})  to Cdate ({?@todate})

then Sum ({TPr_ProcedureReimbursement;1.Charges}, {@Group Program})
else 0
This is what I created for year to date
if date(Minimum ({TPr_ProcedureReimbursement;1.DateTrans}, {@Group Program})) in date(Year({?@todate})-1,1,1) to DateAdd('y',-1,{?@todate})

then Sum ({TPr_ProcedureReimbursement;1.Charges}, {@Group Program})
else 0
This is ignoring the date and jusr sums al charges by program
Any guidance would be appreciated.
0
SequestTech
Asked:
SequestTech
  • 3
1 Solution
 
mlmccCommented:
Are you using this in Crystal or in the SQL?

Your selection formula should be

{TPr_ProcedureReimbursement;1.DateTrans} >= date(Year({?@todate}),1,1)  AND
{TPr_ProcedureReimbursement;1.DateTrans} <= ,{?@todate}

Why were you subtracting 1 from the year?
Are you tring to get last year's data?

Is ToDate a range?

mlmcc
0
 
James0628Commented:
Are you using a stored procedure or just reading tables directly in your report or ...?  As mlmcc mentioned, the record selection in your report, or the WHERE in your stored procedure, needs to include the whole year (however you define that) for the YTD part.

 As for your formulas, it depends on what {?From Date} and {?@todate} are, and what data the report is reading, but trying to use Minimum is probably at least part of the problem.

 I'm guessing that {?From Date} and {?@todate} are the starting and ending dates for the period.

 For the period formula:
 The report will have to read data for the whole year to calculate the YTD total.  That means that the minimum date for each {@Group Program} will probably be some time earlier in the year (before the current period), so the minimum date won't be between {?From Date} and {?@todate}, so you get 0 for the period formula.


 For the YTD formula:
 > This is ignoring the date and jusr sums al charges by program

 That would normally be what you want, if the report is only reading the data for the current year (up to {?@todate}).  If the report includes data after {?@todate}, the formula will be comparing the minimum date for each {@Group Program} to see if it falls in the year range, and if it does, it does a sum of _all_ of the records for the group.

 Perhaps you're thinking that the date test in the if-else is applied to the Sum function.  It is not.  Sum ({field1}, {group field}) always returns the total for {field1} from every record in the group.


 If you can have the record selection (or the WHERE in your stored procedure) limit the records to just the ones in whatever you consider to be the "year to date", then you can just do a simple summary of Charges to get the YTD total.  If you need to include records with dates outside of the "year to date", you can use a formula similar to the one below for the period.

 For the period total, create a formula like the following and do a summary for the group on that formula:

if Date({TPr_ProcedureReimbursement;1.DateTrans}) in
 Cdate ({?From Date})  to Cdate ({?@todate}) then
  {TPr_ProcedureReimbursement;1.Charges}


 James
0
 
SequestTechAuthor Commented:
Don't close. I am just getting back to this report and i need to evaluate the answers that I receievd.
0
 
mlmccCommented:
You are telling it to sum all the records in the group not just those that meet your date criteria.

Try something like

if date(Minimum ({TPr_ProcedureReimbursement;1.DateTrans}, {@Group Program})) in date(Year({?@todate})-1,1,1) to DateAdd('y',-1,{?@todate}) then
   {TPr_ProcedureReimbursement;1.Charges}
Else
   0

Similarly for the other formula.

You can then use a running total on the formula to get the total.

Crystal Summary funtion work on the entire recordset or the specified group.  You probably have records in the group that don't meet the date criteria.

mlmcc
0
 
mlmccCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now