Fuel Mileage Calculation

guamlenahans

Board Regular
Joined
Oct 25, 2006
Messages
113
Hi,
I have a table where i track fuel purchased for 7 vehicles. Vehicles are tracked by plate number. My columns are: Date, Vehicle, Gallons, Cost, Total Cost, and odometer. We enter them row after row and I pivot out the gallons for each vehicle. I'm trying to add two columns where I will factor in the miles driven and the miles per gallon. I will need the formula to look back at the last entry for the vehicle and calculate the miles driven between then and the latest fill up based on the odometer readings. I cant figure out how to do that.

Ideas?

Thanks

Rob
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Based on how yuo desscribe your sheet, I would suggest using vlookup to get the odometer difference, assuming that your table fills columns A:G, with headers in row 1, in H2 enter and fill down

=IFERROR(F2-VLOOKUP(B2,B$1:F1,5,0),"")

Then in I2 and fill down for the MPG

=IF(H2="","",C2/H2)
 
Upvote 0
Thanks Jason. tried it but not working. My sheet look like this:

1585684261266.png
 

Attachments

  • 1585684223329.png
    1585684223329.png
    39.9 KB · Views: 8
Upvote 0
The second formula is wrong, I miscounted the columns and had the division in reverse, it should be this in H2

=IF(G2="","",G2/C2)

The first formula is correct, but it needs to go into G2 instead of H2 before filling down.
 
Upvote 0
The first row for each vehicle will be blank as there is no history, but after you fill it down the subsequent rows should show results.

edit:- looking at your screen capture, the first result should be row 7.
 
Upvote 0
Here is another option that seems to work for mileage. If there is not a previous record it just returns odometer reading.

Book1
ABCDEFG
1DateVehicleGallonsCostTotalOdometerMiles
27/1/2019Veh14300043000
37/3/2019Veh22000020000
47/3/2019Veh35600056000
57/1/2019Veh43500035000
67/8/2019Veh143275275
77/17/2019Veh61000010000
87/18/2019Veh78950089500
97/24/2019Veh83560035600
107/25/2019Veh220400400
118/6/2019Veh143915640
128/13/2019Veh356388388
138/14/2019Veh789832332
148/19/2019Veh144156241
Sheet1
Cell Formulas
RangeFormula
G2:G14G2=F2-IFERROR(INDEX($F$2:F2,AGGREGATE(14,6,(ROW($F$2:F2)-ROW($F$2)+1)/($B$2:B2=B2),2)),0)
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top