Previous registration to get the difference

I have a table with the fields Date, Machine Code, Hour Meter and Number of Gallons shipped; I need to calculate the average consumption between each fuel dispatch, subtracting the current hourmeter minus the previous hourmeter; I have more than 6 thousand records and I get the current record with MAX (hour meter), but I don’t know how to get the previous hour meter, how can I do the query with SELECT ().

You can read the previous hour meter for example like…
LOOKUP(MAXROW(“TableName”,“Date”,[Machine Code]=[_THISROW].[Machine Code]),“TableName”,“KeyColumn”,“Hour Meter”)

1 Like

Thank you very much, I will try, I will comment on the results.

Aleksi: The expression worked very well for me, but I get the highest value, but I need the value before the highest value


      ([_THISROW].[Machine Code] = [Machine Code]),
      ([_THISROW].[Date] > [Date])
  “Hour Meter”

@Luis_Rodriguez You are probably using your formula now in App formula. For me it sounds that you need that in initial value and then the Date evaluation is not needed. Though it depends where do you do the calculation.

THIS IS THE TABLE I NEED TO GET ( the column in yellow is the query)

Thanks Steve, I attach an image of what I need, the column in yellow is data that I need to obtain, thanks for your support

If you type this formula LOOKUP(MAXROW(“TableName”,“Date”,[Code]=[_THISROW].[Code]),“TableName”,“KeyColumn”,“Current Reading”) into your initial value, it will read the previous reading when new record is created. Please use your own table and key column name with the formula.

Remove the space between _ and THISROW. In fact, remove all spaces that aren’t within column or table names.

Excellent, with this formula I will solve many problems I had, thanks Steve

1 Like

Excellent, with this formula I am going to solve many problems I had, thanks Aleksi, I removed the blanks