Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 month rolling average percent

Status
Not open for further replies.

azoe

Technical User
Feb 21, 2005
175
US
I'm using a stored procedure, SQL database, CR 11.

What I want to do:
In the last column get a 3 month rolling Net percent based on the dates the user picks. It doesn't have to start until the 3rd month displayed. See example below. How can I make that happen?

What I have now:
a report that groups by year and then month and in group footer2 shows total charges, payments, and adjustments
and the Net percent for the month. The user picks a beginning and ending date.
Thank you

Code:
Sample:
        Chgs      Pmts      Adj     Net%      Want 3      
                                              Mo Rolling Average Net%
2006  
  Jan 2,244.00   -1,523.83  -894.25   107%   nothing needed here(Nov & Dec not shown)
  Feb 2,352.55   -1,463.38  -768.96    95%   nothing needed here(Dec not shown)
  Mar 2,100.00   -1,500.00  -400.00    90%   97%  (I think - not sure if my math is right)
  Apr 3,000.00   -1,500.00  -500.00    66%   83%

//@PercentNetCollections
ABS(Sum ({@PaymentsAndAdjustments}, {@Months}) % ({#Charges}) )

//@PaymentsAndAdjustments
{@Payment} + {@Adjustment}


//#Charges
Running total that sums charge amount on change of field chargeID reset on change of Month group.


//@Payment
If isnull({aa_dch_PercentOfGrossCollections;1.PaidAmt})
Then 0
Else {aa_dch_PercentOfGrossCollections;1.PaidAmt}

//@Adjustment
If {aa_dch_PercentOfGrossCollections;1.TranType} = 'A'
Then
If isnull({aa_dch_PercentOfGrossCollections;1.AdjAmt})
then 0
else {aa_dch_PercentOfGrossCollections;1.AdjAmt}
Else 0


//@Months **This one is a mess because we didn't go by a calendar month in 2005 but we do in 2006
//not required to go into 2004
if {aa_dch_PercentOfGrossCollections;1.ClosingDate} < #01/08/2005 00:00#

Then "Month Not Available"
Else

If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #01/08/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #02/02/2005 00:00#
Then "01 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #02/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #03/02/2005 00:00#
Then "02 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #03/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #04/02/2005 00:00#
Then "03 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #04/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #05/03/2005 00:00#
Then "04 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #05/03/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #06/02/2005 00:00#
Then "05 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #06/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #07/02/2005 00:00#
Then "06 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #07/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #08/02/2005 00:00#
Then "07 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #08/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #09/02/2005 00:00#
Then "08 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #09/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #10/04/2005 00:00#
Then "09 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #10/04/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #11/02/2005 00:00#
Then "10 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #11/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #12/02/2005 00:00#
Then "11 / 05"
Else
If {aa_dch_PercentOfGrossCollections;1.ClosingDate} >= #12/02/2005 00:00# and

{aa_dch_PercentOfGrossCollections;1.ClosingDate} < #01/01/2006 00:00#
Then "12 / 05"

Else
If (year({aa_dch_PercentOfGrossCollections;1.ClosingDate})) > 2005
Then
{@TwoDigitMonth} & " / " & right(totext(year({?@EndDate})),2)
 
I haven't gotten any further on this. I've been reading articles and was hoping the Previous function might help me so I tried this:
Code:
if isnull(Previous(ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt})))
or isnull(Previous(Previous(ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt})))) 
then 0
Else 

ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt}) + Previous(ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt})) + Previous(Previous(ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt})))

But Crystal tells me "a field is required here" and it highlights this: ABS({aa_dch_PercentOfGrossCollections;1.ChgAmt}

I tried removing ABS but it still highlights Previous({aa_dch_PercentOfGrossCollections;1.ChgAmt} and says a field is required here.

Maybe Previous isn't the way to go anyway. Any ideas?
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top