I need to fetch the last record and subtract value from current record field entry

I need to fetch the last record and subtract value from current record field entry

I have a form that I am using to monitor a water meter. I want to fetch the previous reading and subtract it from the current reading to show gallons used. 

It seems so simple but I can't even get it to fetch the previous reading! Please help.

Here is my script:


LastRecord = Water_Meter[ID != 0] sort by Added_Time desc;
input.Last_Reading = LastRecord.Meter_Reading;
input.Gallons_Used = input.Meter_Reading - input.Last_Reading;