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 ().

Solved Solved
0 11 377
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

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

View solution in original post

11 REPLIES 11

You can read the previous hour meter for example likeโ€ฆ
LOOKUP(MAXROW(โ€œTableNameโ€,โ€œDateโ€,[Machine Code]=[_THISROW].[Machine Code]),โ€œTableNameโ€,โ€œKeyColumnโ€,โ€œHour Meterโ€)

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

Try:

LOOKUP(
  MAXROW(
    โ€œTableNameโ€,
    โ€œDateโ€,
    AND(
      ([_THISROW].[Machine Code] = [Machine Code]),
      ([_THISROW].[Date] > [Date])
    )
  ),
  โ€œTableNameโ€,
  โ€œKeyColumnโ€,
  โ€œHour Meterโ€
)

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

@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)

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.

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

Steve
Platinum 4
Platinum 4

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

Top Labels in this Space