Retrieve previous row Record to subtract from current row above (water consumption)

OHB

New Member
Joined
Oct 11, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all Members of the Forum,
I built a query where I want to calculate the difference between two rows in the same column.
The previous Record is deducted from the next record just the row above and the difference between both value appear in the result of another column (same row).

My Access SQL formula is as follow :

SELECT t_compteur.Consomateur, t_compteur.Description, t_releve.Date_releve, t_releve.Releve_m3,
(SELECT MAX(Releve_m3) from t_releve AS Alias WHERE Alias.Releve_m3 < t_releve.Releve_m3 GROUP BY t_compteur.Description) AS PrevReleve_m3, t_releve.Releve_m3-PrevReleve_m3 AS Difference
FROM t_compteur RIGHT JOIN t_releve ON t_compteur.N_compteur = t_releve.N_compteur
ORDER BY t_compteur.Consomateur DESC , t_compteur.Description DESC , t_releve.Date_releve DESC;

Capture.JPG

The formula works well with some data but not at all with some other numbers…
What is wrong with the selection of data for picking wrong number?
I couldn’t identify the interference and I am wondering if I use the correct formula with the Max() function ?
Would there be another way to pass-by this bug or another function/formula to be used ?

Thanks for your support and I appreciated all your useful advices in this Forum.
Kind regards,
O.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top