I have searched this forum and also googled this and found a few results but nothing that really made it very clear to me.
I have a table with an index field. I need a query that performs a calc and uses the previous record (Index - 1) in the calculation.
I know how to lookup the previous record (or more accurately the record with index-1) from the original table.
The problem that I have is I need to look up the previous calculated value and this can only come from the query that I am writing and not a pre-existing table.
tblData
Index ----Data
1 -------0.95
2 -------0.90
3 -------0.85
4 -------0.91
5 -------0.88
6 -------0.93
7 -------0.92
8 -------0.95
9 -------0.88
10 ----- 0.96
So if I am creating Query1, I have these 2 fields:
Index: [tblData].[Index]
qryData:IIF([tblData].[Index]=1,[tblData].[Data], {somefunction} * DLOOKUP("qryData", "Query1", "[tblData].[Index] = " & [tblData].[Index] -1)
The query is not working and I suspect it is because I am referencing itself in my DLookup formula. How can this be done?
just for interest I am calculating an exponential moving average here, which I just summarise as {somefunction} in the above example for simplicity.
I have a table with an index field. I need a query that performs a calc and uses the previous record (Index - 1) in the calculation.
I know how to lookup the previous record (or more accurately the record with index-1) from the original table.
The problem that I have is I need to look up the previous calculated value and this can only come from the query that I am writing and not a pre-existing table.
tblData
Index ----Data
1 -------0.95
2 -------0.90
3 -------0.85
4 -------0.91
5 -------0.88
6 -------0.93
7 -------0.92
8 -------0.95
9 -------0.88
10 ----- 0.96
So if I am creating Query1, I have these 2 fields:
Index: [tblData].[Index]
qryData:IIF([tblData].[Index]=1,[tblData].[Data], {somefunction} * DLOOKUP("qryData", "Query1", "[tblData].[Index] = " & [tblData].[Index] -1)
The query is not working and I suspect it is because I am referencing itself in my DLookup formula. How can this be done?
just for interest I am calculating an exponential moving average here, which I just summarise as {somefunction} in the above example for simplicity.