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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't add an amount from details to a shared variable

Status
Not open for further replies.

travelerII

Technical User
Jun 4, 2009
66
US
I am using Crystal 10.
I am creating a sales report and we record other income in two ways. On the invoice line with a dimension of OTH and in the invoice elements.
I have created a subreport to get the amount from the invoice elements and have used a shared varible to place it in the main report. I need to be able to add this amount to the amount from the invoice line with the dimension of other. I created a report to get the amount from the details section.
if {SINVOICED.CCE2_0}="OTH"
then({SINVOICED.AMTNOTLIN_0}*{SINVOICE.SNS_0})
else 0
Placed in the detail section this returns the correct amount. Then I wrote the following formula to get the amount allocated to the proper time period
if Year({SINVOICED.INVDAT_0}) = Year({?rptdat}) then
{@Amount Other}
else
0
However when I try to add it to the shared variable
(whileprintingrecords;
shared numbervar YTDOther;)
+
{@Current YTD Other}
I only get the amount of the original shared variable.
If I place the Current YTD Other formula
if Year({SINVOICED.INVDAT_0}) = Year({?rptdat}) then
{@Amount Other}
else
0
in any other section of the main report besides details it returns 0.
How can I get this to work?
Any help is greatly appreciated.
 
Try writing it like this:

whileprintingrecords;
shared numbervar YTDOther;
YTDOTher +{@Current YTD Other}

But you haven't said where you are placing this formula. Where is the subreport located, and in what section is the shared variable supposed to be located? If it is in a group section, then change the formula to:

whileprintingrecords;
shared numbervar YTDOther;
YTDOTher + sum({@Current YTD Other},{table.groupfield});

-LB
 
I tried both formulas with no luck.
The subreport is in group footer #1b and the shared variable is in Report footer b.
I have the data grouped by dimension; MFG, STK, etc., and I have a similar subreport for freight and was able to add the shared variable for freight to the sum of the group dimension for freight with no problem. However when I tried to do the same thing with "Other" I discovered it would only work if I moved "Other" to the bottom of the dimension grouping and then the "Freight" formula wouldn't work. Apparently how the grouping is arranged effects the formulas performance. That is why I am trying to come up with a work around.
 
If the subreport is linked on the groupfield, then in the report footer, you would only get the shared variable from the last group instance. There is a way to carry the shared variable into the report footer, but I would have to understand which shared variable you wanted carried forward (which main report group instance contains the correct value). If the value you want is in an "Other" main report group, then you could do something like this:

whileprintingrecords;
shared numbervar YTDOther;
numbervar mainother;
if {table.group} = "Other" then
mainother := YTDOther else
mainother := mainother;

Then in the report footer, you can use:

whileprintingrecords;
numbervar mainother;
mainother + sum({@Current YTD Other});

This assumes that you want to sum {@current ytd other} for all records in the report.

-LB
 
The subreport that provides the data for "Other" is linked to the main report by reference date which is determined by the following formula
If (DayOfWeek ({?rptdat}) = 2 ) then {?rptdat} - 3
else {?rptdat}-1
So I believe my answer to your first question would be no it isn't linked on a group field, unless I am misunderstanding you.
The main report shows sales in the various dimensions; MFG, STK, etc. by current date, month to date, previous year month to date, year to date and previous year year to date.
Then my shared variables contain the same categories but from the subreport. I want to be able to add Daily Freight from the main report to Daily Freight from the shared variable, and so on for all date categories and report the total on one line. I can currently get all the correct data but there would be two lines for freight and two lines for other because of there different sources.
Hope this makes sense.
With the suggested formulas you gave where should they be placed? I assume the second one in the report footer but where should I put the first one?
Thanks again for your help.
 
Please do not refer to "lines", but instead to sections. Are both subs placed in the dimension group? Please show some sample data that shows the dimension groups, the main report values, and the shared variable values, and then also the calculation you are trying to achieve. I can't tell whether you are looking for a group level result or a report level result. Are you trying to add values from different groups? I'm lost.

-LB
 
Sorry I am having trouble explaning myself. I am sure there is a way to do what I am trying to do if I could only be more clear.
Thank you for you time and effort.
I have decided to go with a different approach to the problem entirely. I seems to be working so I will go with it.
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top