Appreciate help if anybody let me know how to acheive \"PreviousValue\" cloumn as shown below in MSAccess
I have records stored in table for various categories other tha
You can use a subquery to get the previous value.
SELECT tx.id,
tx.name,
tx.office,
tx.product,
tx.overall,
tx.month,
tx.VALUE,
tx.previous,
Nz((SELECT TOP 1 [value]
FROM tablename t
WHERE t.id = tx.id
AND t.name = tx.name
AND t.office = tx.office
AND t.product = tx.product
AND t.overall = tx.overall
AND t.month < tx.month
ORDER BY t.month, rnd(t.id) DESC), 0) AS Prev
FROM tablename tx
ORDER BY tx.month;
New query based on changed, very sparse, sample data
SELECT tz.id,
tz.name,
tz.office,
tz.product,
tz.date,
tz.month,
tz.VALUE,
Nz((SELECT TOP 1 [value]
FROM tablename t
WHERE t.id = tz.id
AND t.name = tz.name
AND t.office = tz.office
AND t.product = tz.product
AND t.date < tz.date
ORDER BY t.date DESC), 0) AS Prev
FROM tablename tz
ORDER BY tz.date;