I need help with a gas mieage formula.

I have it working except when you make a partial fill up the mileage is messed up to that fill up but the average is fine. Is there away to make it work of a per fill up basis but keep the average? This is more of can it be done.