Link to home
Start Free TrialLog in
Avatar of Jennifer Barman
Jennifer BarmanFlag for United States of America

asked on

How do I create multiple subreports to link to 1 main report by different dates and totals

I need to create a crystal report which will show different categories, and then a total of revenue for these catogories and then a seperate subsection of Cost of Goods

The Main report should look something like this

Number    Name      Current Month   YTD    Last YR Month    Last YR YTD
    1              a               1,000            12,000      988                  10,222
    2              b               2,000            15,000      1200                19000
    3              c                680               4000         500                  2800

Just an example..It would be good to probably prompt for at least the Month they want to see, everything else can feed off of that as far as formulas.
Avatar of Jennifer Barman
Jennifer Barman
Flag of United States of America image

ASKER

I forgot to add a total for each of these at the last line...
Avatar of Mike McCracken
Mike McCracken

Why do you need a subreport?

mlmcc
Well I suppose if there is a way to accomplish the above I am all for it..
The user will need to be able to put the parameter in ... maybe I am making it more complicated then it needs to be..
I guess the issue is that if I have the user limit the parameter to that particular month.. then how do I get the other fields to see past data without using a seperate query-report??
Have the user input a date and use it to select records.

{DateField} Between Date(Year({?DateParameter}),1,1) AND {?DateParameter})
OR
{DateField} Between Date(Year({?DateParameter})-1,1,1) AND Date(Year({?DateParameter})-1,Month({?DateParameter}),Day({?DateParameter})))

In the report you can use formulas
CurrentYTD
If Year({DateField}) = Year({?DateParameter}) then
    {AmountField}
Else
    0

CurrentMonth
If Year({DateField}) = Year({?DateParameter}) AND month({DateField}) = Month({?DateParameter})    then
    {AmountField}
Else
    0

Similarly for PastYTD

If Year({DateField}) = Year({?DateParameter})-1  then
    {AmountField}
Else
    0

PastMonth
If Year({DateField}) = Year({?DateParameter})-1 AND month({DateField}) = Month({?DateParameter})    then
    {AmountField}
Else
    0


Use thise formulas to get the totals for the report

mlmcc
I will test this theory.. I appreciate your assistance.
This does not seem to be working.. maybe I am not understanding it correctly.

I have created an input parameter called DateRange this is in the select expert
Where date is equal to {dateRange} so now the enitre report is "only" pulling that data into the report.. it can't go backwards.. that is why I am pretty sure I need to enter in a subreport.. something not tied to the main data..
My formulas assume a single date field for the rnd date of the period then you use the first formula to select records

//This year's records
{DateField} Between Date(Year({?DateParameter}),1,1) AND {?DateParameter})
OR
//Last Year's records
{DateField} Between Date(Year({?DateParameter})-1,1,1) AND Date(Year({?DateParameter})-1,Month({?DateParameter}),Day({?DateParameter})))


If you want to enter a range then
{DateField} In {?DateRange}
OR
{DateField} +365 IN  {?DateRange}

mlmcc
The basic idea is to "adjust" the date field (or parameter) values so that you can use the same parameter to include the records for last year.  If your daterange parameter actually has a range of dates, you can (as in mlmcc's last formula) add 1 year to the date field and that will include any records from last year that fall in that range.  You could subtract 1 year from the range instead, but adding a year to the field is a little bit simpler.

 FWIW, you might want to give some thought to how you want to handle leap years.  For example, if you use 02/29/2012 as the end of your date range, what should be the cutoff point in 2011 (the prior year)?  02/28, or 03/01?  And if you use 02/28/2013 or 03/01/2013 as the end date, which one of those should include 02/29/2012 in the prior year?

 Also, I have one correction to mlmcc's first formula.  You need to use IN, instead of BETWEEN (unless they've added a BETWEEN operator in some version after CR 10).

 James
so in the actual select expert I should be using the parameter something like this???

{Command.RevGLAccountNumber} = "4100" and
{Command.Date} IN Date(Year({?DateRange})-1,1,1) AND Date(Year({?DateRange})-1,Month({?DateRange}),Day({?DateRange}))


I am getting an error .. but I am still working with it.
What error are you getting?


That will get last years data.  You need the same to get this years data.  That works if the parameter is a single date.

{Command.RevGLAccountNumber} = "4100"
and
(
{Command.Date} IN Date(Year({?DateRange})-1,1,1) AND Date(Year({?DateRange})-1,Month({?DateRange}),Day({?DateRange}))
OR
{Command.Date} IN Date(Year({?DateRange}),1,1) AND Date(Year({?DateRange}),Month({?DateRange}),Day({?DateRange}))
)

mlmcc
I have added it to my select expert just as you wrote above..
{Command.RevGLAccountNumber} = "4100"
and
(
{Command.Date} IN Date(Year({?DateRange})-1,1,1) AND Date(Year({?DateRange})-1,Month({?DateRange}),Day({?DateRange}))
OR
{Command.Date} IN Date(Year({?DateRange}),1,1) AND Date(Year({?DateRange}),Month({?DateRange}),Day({?DateRange}))
)


I have the parameter set as follows see image. User generated image User generated image
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay.. so I think I got the data in now.. thats great.. now i need to get my columns to show the right data..

Now I have these totals grouped using the running total fields.. can I still use the first response for breaking these numbers up?
The totals are not working out right.. I am starting with just the current month.
If Year({Command.Date}) = Year({?DateRange}) AND month({Command.Date}) = Month({?DateRange})    then
   {Command.Amount}
Else
    0

I need to get the full date.. like Aug 1 2011 thru Aug 31 2011.. I think it is only returning the exact date!!.. 8/1/2011..
WHat are you entering as the date?

The filter will return all data through the date you enter.  If you want 1 Jan - 31 Aug then enter 31 Aug as the date.

mlmcc
ahh got it!! :)
Very helpful .. stuck with me to the end! :)
About that error: I noticed the BETWEEN.  Didn't notice the AND.  :-)  Makes sense that it would be there.  I just didn't look that carefully.

 James
Thanks James! :)
No problem.  Also, as I mentioned earlier, you might want to give some thought to leap years (if you haven't already) and decide if you want to handle those in a specific way.

 James