Calculate Monthly Miles Driven Based on Multiple Options from Two Columns of Data

jomilo

New Member
Joined
Mar 10, 2011
Messages
16
I apologize if the above Post Topic Title is weird or misleading. I don't really know how to succinctly identify my need in a single line of text. But here is what I'm trying to do:

I have a monthly expense report worksheet that tracks gas receipts and odometer readings at the time of each gas fill-up. My goal is to extrapolate from the worksheet a way to itemize how many miles were driven per expense report for each of the vehicles included in the report.

(Background: We have one person that is responsible for filling up all the company's trucks and he has to fill out an expense report each month that includes not only the gas receipts but all other job-related receipts that he is involved in. We also want to track the mileage driven during that month for each of our vehicles. So he fills out an expense report that includes the date, 'purchased from', the cost, the vehicle filled up (via a license plate number), and the odometer reading at the time of the fill up.)

So let's say I have 2 columns with 10 rows each. In Column A each of the cells has a data validation drop-down list that requires the user to select a license plate number that corresponds to the vehicle that was just filled up at the gas station. There are 3 possible license plates numbers from which to choose that correspond to 3 separate vehicles.

In Column B, the user is to enter the odometer reading of the vehicle referenced in Column A at the time the vehicle was filled with gas.

My goal is to have a place at the bottom of the worksheet that can look at Column B and determine the mileage driven for each of the 3 vehicles (based on the license plate number selected in Column A) and then return the result of that calculation. So at the end, I can have separate cells that shows that, for example, Vehicle 1 was driven 500 miles during the month, Vehicle, 2 was driven 250 miles during the month, etc. This may need to expand to up to 8 vehicles.

The difficulty is that the vehicles selected in Column A will not necessarily be consecutive and will often occur in the expense report multiple times. (The same vehicle may be filled up 2 or 3 times during the month.) For example, on day 1, it may have Vehicle 1 with an odometer reading of 5,000 and then on day 2 Vehicle 2 is listed with an odometer reading of 7,500. Then on day 6 and 10, there may be receipts and odometer readings for Vehicle 1 again, with Vehicle 3's information and other non-vehicle receipts being filled in for the other days. So without the selected data sets being consecutive, I can't figure out a way to accomplish what I'm trying to do.

Is there a way to perform such a calculation so that Excel can determine the specific vehicle by what is selected in Column A and then based on the corresponding odometer readings in Column B provide me with a Total Miles Driven for the month (or, per report) for each vehicle included even though the vehicles listed are not listed consecutively and may be listed multiple times?

I hope I explained this well enough. Please advise if clarification is needed. Thank you for your help.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello,

Try this array* formula out:

=MAX(IF(A1:A8="ABC",B1:B8)-MIN(IF(A1:A8="ABC",B1:B8)))
Change the ranges of A1:A8 and B1:B8 to be as big as you want.
Where "ABC" shows up, you can replace with whatever license plate value you want.

This formula does not take into account the month, I will start working on that.

*After you put the formula into a cell, you must press ctrl + shift + enter
 
Upvote 0
Thanks for the quick response, blaow. But before wasting too much of your time, please look at the attached image. I hope it more accurately demonstrates what I'm looking for. Please advise.

<!-- copy and paste. Modify height and width if desired. -->
 
Upvote 0
jomilo, use these formulas.

Vehicle 1
=MAX(IF(G:G="Lic#1",H:H)-MIN(IF(G:G="Lic#1",H:H)))

Vehicle 2
=MAX(IF(G:G="Lic#2",H:H)-MIN(IF(G:G="Lic#2",H:H)))

Vehicle 3
=MAX(IF(G:G="Lic#3",H:H)-MIN(IF(G:G="Lic#3",H:H)))

REMEMBER that after you copy these formulas into the cells, press CTRL + SHIFT + ENTER
 
Upvote 0
Unfortunately, I must revisit this issue due to Excel refusing to allow me to change or add anything without providing me a #VALUE error. I hate to restate everything, but I really don't know how to proceed, especially because I am not allowed to upload an attachment of my Excel document. Looking at the previous posts and responses in this thread may assist you. Here's what's going on now:

I used blaow's advice and created code for 7 vehicles for which I'm tracking mileage. An example line of code is listed below. This line of code works, as well as the other 6 lines of similar code - but only so long as I leave it alone. If I change the "123 ABC" to "456 DEF" or anything else, I get a #VALUE error. If I try to copy the formula to create a new vehicle ID, even if the ID itself has not changed yet, I get the error. It's like everything is just fine as long as I don't change or modify anything. Obviously, that makes it impossible to modify my document or add new vehicles.

{=MAX(IF($G$6:$G$91="ABC 123",IF($I$6:$I$91>0,$I$6:$I$91)))-MIN(IF($G$6:$G$91="ABC 123",IF($I$6:$I$91>0,$I$6:$I$91)))}

I'm at a complete loss. If there was a private email I could send the document to so that I could have someone view the actual document, I think that would be best. Without that option, I'm doing the best I can to explain what's going on. I would appreciate any help that could be provided. Thank you.
 
Upvote 0
I don't know if I posted my previous post (or this one, for that matter) correctly, because no one responded or even looked at my most recent inquiry, which is unusual for this site. Not that I'm anything special. But there are a lot of special people out there that enjoy helping. Oh, well. I did find an answer to my problem, and I wanted to post it here just in case someone could possibly benefit.

Earlier in this thread blaow said "REMEMBER that after you copy these formulas into the cells, press CTRL + SHIFT + ENTER." Well, it turns out that is essential. I tried adding the "{" and "}" symbols before and after the formula just like it shows in the other working formulas. But for some reason it didn't work. The only way I could get a new formula in the form of "={=MAX(IF($G$6:$G$91="ABC 123",IF($I$6:$I$91>0,$I$6:$I$91)))-MIN(IF($G$6:$G$91="ABC 123",IF($I$6:$I$91>0,$I$6:$I$91)))}" to work was to press CTRL + SHIFT + ENTER after the formula is entered in the formula bar. As long as I do that, I have no problems. Weird, but true.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,793
Members
449,048
Latest member
greyangel23

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