the expressionThen subtract instead of add.
You need a field named StartHours then in the query you would use [NewHours]-[StartHours]Thanks for reply
I need to running subtract not Total
the DB contains Acutial Data
1571
1572
1573
the first row should be 0
the second Should be 1
The third should be one
it's not accumulated total
I need to subtract the Total
I can do accumulated total using report running sum = over all
I don't need running sum
----------
I need running minus
Can you give us some detail of what your data is about and the need of these calculations. Perhaps a screen shot of your relationships as well.I need to subtract the first cell from the second and the second from the third etc
مرة أخرى، التوضيح ليس هو أفضل طريقة للتواصل.
أظهر لي بالضبط كل البيانات التي تريد أن ينتجها الاستعلام بناءً على ما هو موجود في الجدول الذي قمت بتحميله. إذا لزم الأمر، التقط لقطة شاشة للاستعلام الحالي وضع القيم المتوقعة الصحيحة حيث يجب وضعها.
You need to use the database you uploaded to demonstrate. The database you uploaded has no ID=21. So either upload that database or provide a screenshot using the existing one.
ID | NewHours | DateAdd | Minus |
---|---|---|---|
1 | 1571 | 12/31/2024 | 0 |
14 | 1572 | 1/2/2024 | 1 |
20 | 1573 | 1/3/2025 | 1 |
21 | 1580 | 1/3/2025 | 7 |
You want Subtract to be the result? You want the difference between consecutive records? This not really a "running" value.
This is not simple in Access. Review http://allenbrowne.com/subquery-01.html#AnotherRecord
Consider:
SELECT TableHours.ID, TableHours.NewHours, TableHours.DateAdd,
[NewHours] - Nz(DMax("NewHours","TableHours","[ID]<" & [ID]), NewHours) AS Minus
FROM TableHours;
SELECT TableHours.ID, TableHours.NewHours, TableHours.DateAdd,
[NewHours]-Nz((SELECT TOP 1 NewHours FROM TableHours AS Dupe WHERE Dupe.ID<TableHours.ID ORDER BY ID DESC),NewHours) AS Minus
FROM TableHours;
ID NewHours DateAdd Minus 1 1571 12/31/2024 0 14 1572 1/2/2024 1 20 1573 1/3/2025 1 21 1580 1/3/2025 7
The second version might be a little faster but both will perform slowly with large dataset.
Now in a report you could do a RunningSum on the Minus field.