Google Sheets – Use Two Values from One Column to Fill Another Column

google sheets

I'm trying to work out how far I travel on a tank of petrol. I've set a column to display the mileage at the time I enter the petrol station, and I want to display the difference between the two values in the next column.

Example:

Mileage is in column F and tank mileage is in column G.

I can get it to calculate the one tank, but I want Column G to auto calculate the tank mileage each time I add to the Total Mileage column.

This is how far I've got. located in Cell G3

=ARRAYFORMULA(IF(F3:F,(F3-F2:F),""))

It subtracts the value in F3 from the value in F2 to show me how many miles I've travelled on one tank of fuel. But I can't figure out how to make it work more than once.

I hope I'm making sense, I've been self-teaching myself Google Sheets all week and thanks to this site I've come this far. I'm probably over-engineering it.

Any help would be appreciated.

Best Answer

Short answer

=ARRAYFORMULA(IF(F3:F,(F3:F-F2:F),""))

Explanation

Both parameters of a subtraction operation should be arrays in order to return an array.