• Status: Solved
• Priority: Medium
• Security: Public
• Views: 300

# 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.
0
Jennifer Barman
• 14
• 6
• 3
1 Solution

Author Commented:
I forgot to add a total for each of these at the last line...
0

Commented:
Why do you need a subreport?

mlmcc
0

Author Commented:
Well I suppose if there is a way to accomplish the above I am all for it..
0

Author Commented:
The user will need to be able to put the parameter in ... maybe I am making it more complicated then it needs to be..
0

Author Commented:
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??
0

Commented:
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
0

Author Commented:
I will test this theory.. I appreciate your assistance.
0

Author Commented:
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..
0

Commented:
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
0

Commented:
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
0

Author Commented:
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.
0

Commented:
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
0

Author Commented:
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.
0

Commented:
Sorry we both got it wrong
It should be
{Command.RevGLAccountNumber} = "4100"
and
(
{Command.Date} IN Date(Year({?DateRange})-1,1,1) TO  Date(Year({?DateRange})-1,Month({?DateRange}),Day({?DateRange}))
OR
{Command.Date} IN Date(Year({?DateRange}),1,1) TO  Date(Year({?DateRange}),Month({?DateRange}),Day({?DateRange}))
)

mlmcc
0

Author Commented:
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?
0

Author Commented:
The totals are not working out right.. I am starting with just the current month.
0

Author Commented:
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..
0

Commented:
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
0

Author Commented:
ahh got it!! :)
0

Author Commented:
Very helpful .. stuck with me to the end! :)
0

Commented:
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
0

Author Commented:
Thanks James! :)
0

Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.