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

Q

Status
Not open for further replies.

neronikita

Technical User
Feb 20, 2002
159
US
I am baffled. I have a report (work completed) with two subreports (parts and hours). Using variables, I created several formulas to pull totals from each subreport and add them up in the main report. It works... with a little flaw. If there are not any parts and/or hours for the current job, it pulls the info from the previous job in (so it will never show 0, even if it should). This throws off my totals.

The parts report is using the following formulas:

@totalpartscost:
{PartsUsed.numpartsused}*{partslist.cost}

@totalpartsshared:
Shared currencyvar TotalPartsShared;
TotalPartsShared := if ({@TotalPartsCost}) > 0 then (Sum ({@TotalPartsCost}, {DailyVehicleTracking.DailyVehicleTrackingID})) else 0

NOTE: I also tried this without the if/else parts and they work the same

The hours report uses the following formulas:

@overheadcost:
shared currencyvar overheadcost;
overheadcost := Sum ({@calcmechcost})

@alcmechcost:
{@calctime} * {@MechTime}

@calctime:
datediff("s",datetime(currentdate,{@TimeStart}), datetime(currentdate,{@timestop}))

The main report uses:

@totalpartssharedmain:
whileprintingrecords;
shared currencyvar totalpartsshared;
totalpartsshared

@overheadcostmain:
whileprintingrecords;
shared currencyvar overheadcost;
overheadcost

@totalcostfromvar:
whileprintingrecords;
{@overheadcost main} + {@totalpartssharedmain}


So the main totals will work if there are both parts AND hours are in for the given job number. If either are missing, it pulls the number from the previous job number and inserts it, giving an incorrect total. I'm not sure how to make it pull just that job number or use a zero if nothing is found, since I am already telling it to do that (or so I thought).

Please let me know if I need to give more information or explain anything further. I am using Crystal Reports 2008 and SQL Server 2008.

Thanks!

Di

 
You didn't specify the location of your subreports, but let's assume they are in a group header section_b, with the calculation formula in GH_c. In GH_a, you need a reset formula like this:

whileprintingrecords;
shared currencyvar totalpartsshared;
shared currencyvar overheadcost;
if not inrepeatedgroupheader then (
totalpartsshared := 0;
overheadcost := 0
);

-LB
 
Thanks Lbass, I will try that. The subreports are in GroupFooter#2a and groupFooter#2b. Will that make a difference?

Thanks,

Di
 
It seems to be working, as far as I can tell by spot checking. Thank you soooo much! You saved me hours of manual calculations. Now is there any way that I can take that total (@totalcostfromvar) and add that up to a grand total for all jobs per truck and all jobs total for the month? It says that this field can't be summarized....
 
You have to add those using variables as well, with the results showing in the corresponding group footer. Please identify the fields you are grouping on in the main report.

-LB
 
Group one is vehicle number, group two is on vehicle tracking id (basically the job number). I'm already summarizing the job number, now I need to do it by vehicle number, then by whole fleet for the month.

Thanks!

Di
 
So the report is limited to a particular month already and you are not grouping on date?

Change this formula:
//{@totalcostfromvar} for the job group section:
whileprintingrecords;
currencyvar job := {@overheadcost main} + {@totalpartssharedmain};
currencyvar veh := veh + job;
currencyvar tot := tot + job;
job

Then create these formulas:
//{@vehreset} to be placed in the vehicle group header:
whileprintingrecords;
currencyvar veh;
if not inrepeatedgroupheader then
veh := 0;

//{@vehdisp} for the vehicle group footer:
whileprintingrecords;
currencyvar veh;

//{@totdisp} for the report footer:
whileprintingrecords;
currencyvar tot;

-LB
 
No, I filter it for the month that I want to run it for. I would only need a grand total for the year at the end of the year, but I wouldn't need to run the whole report over again. Now that I think of it, I guess I'll need to figure that out too...

Thanks! I'm going to try your formulas above now.

Di
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top