# Formula help needed

Options

Hi guys I need help writing a formula. I'm trying to write a formula in which it calculates the fuel consumption for each truck for that specific date.

What I was trying to say with the formula is that it should look at which truck, date and shift it is today, and then find the same truck and collect the odometer reading that.

So you get the trucks odometer from today minus the odometer reading the same truck filled up the previous time) / the amount of litres from to day.

### Sheet

http://app.smartsheet.com/sheets/V8FgF9WM26prxFM4R66RHxcvP62HFJ2RpGVQX7W1

• edited 03/24/20
Options

This is my current formula

=(Odometer@row - INDEX(Odometer:Odometer, MATCH(MAX(COLLECT(Date:Date, Date:Date, @cell < Date@row, [Truck No]:[Truck No], [Truck No]@row)), Date:Date, 0), 0)) / Litres@row

But it doesn't seem to be working - I've tried finding the error but I can't.

• ✭✭✭✭✭✭
Options

"it doesn't seem to be working"

Is it giving an error or incorrect data?

• Options

=INDEX(Odometer:Odometer, MATCH(MAX(COLLECT(Date:Date, Date:Date, @cell < Date@row, Truck:Truck, Truck@row)), Date:Date, 0), 0)

So you will see in column 15 the data repeats itself and I don't know how to fix that?

• Options

I ran it to see which truck's data it was collecting and as you can see in the image its only Truck 14 and Truck 16's odometer readings

## Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the Formula Handbook template!