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!

Help with mileage calculation formula 1

Status
Not open for further replies.

13maddie

MIS
Aug 23, 2010
4
US
hello-
I'm trying to set up a formula, say @mileage that ={end.mileage}-{start.mileage} that will give me total mileage driven for a given date for a given vehicle.

Do I need to define my daterange 1st? Do I need to define my vehicle #'s?

I am a formula novice (not new to Crystal but new to custom formulas and proper syntax). I'm currently using 8.5.

I want to put my @mileage field in the detail section after my column that represents my end mileage. Or do I put it in the report footer?

Any help is greatly appreciated!

Maddie
 
You could define the date range in your record selection formula. Then insert a group on date and on vehicle (not sure whether you want to see all vehicles per date or all dates per vehicle). But you have to explain whether you have only one mileage field or whether you have a start mileage field and an end mileage field. If they are really separate fields, you can just subtract them in a formula placed in the detail section. Then insert a sum on the formula at the group level.

-LB
 
Thanks LB-I do have 2 separate mileage fields-one for starting mileage, one for ending mileage. I probably want to see all dates by vehicle. I did try to put @mileage in the detail section but when I set the formula up with just the above detail {field 2}-{field 1} with nothing else, it returns with "a number, currency, amount, date, time, or date-time is required here." This occurs in front of my 1st fieldname. That's why I wondered if I need to define the date range to satisfy this error. I'm sure it's a simple syntax issue-I will keep trying different scenarios with your suggestions.

Thanks
 
Please report back with the datatype of each mileage field. You can run your mouse over the field and see the datatype in the tooltip text or browse the field and it will tell you the datatype. I

It's surprising that it is not a number, but if it is not, it is like to be a string, so try:

tonumber(field1)-tonumber(field2)

-LB
 
Hi LB-it is a string datatype for both fields-I will try your suggestion, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top