Hey there,
I'm way out of my league here and hoping for the usual great help here. This is a follow up question to this post:
https://www.access-programmers.co.uk/forums/threads/n-period-moving-average-in-queries.37137/#post-1948362.
From that post, I have a table that has multiple values calculated from a source data table containing VIX stock data. The new table has Autonumber ID, Date, 30-day avg, 10, day avg, a field of the 30d avg/ 10d avg, and two other values that should contain the 300-day of the 5th field and 300-day StDev of the 5th field. I have populated the first 5 fields with an Append query.
I'm trying to figure out how to update the remaining two fields based on select statements of the values in the table.
The source and destination table is named VIX_RiskZ with snippet here:
ID BarDate SMA30 SMA10 SMA30_10 AvgSMA30_10 SDevSMA30_10 RiskZ <--- will be invalid until the previous two fields are populated with non-zero values.
1 11/4/2022 24.55 24.55 1 0 0 #Div/0!
2 11/7/2022 24.45 24.45 1 0 0 #Div/0!
3 11/8/2022 24.81 24.81 1 0 0 #Div/0!
4 11/9/2022 25.13 25.13 1 0 0 #Div/0!
5 11/10/2022 24.81 24.81 1 0 0 #Div/0!
The following query seems to generate proper values, although I can't verify them for certain until I get them into the table for the final calculated field, RiskZ to do its magic:
SELECT b.BarDate, Round((SELECT AVG(SMA30_10) from VIX_RiskZ where ID BETWEEN b.ID and b.ID-299), 2) AS AvgSMA30_10, Round((SELECT StDevP(SMA30_10) from VIX_RiskZ where ID BETWEEN b.ID and b.ID-299), 2) AS SDevSMA30_10
FROM VIX_RiskZ AS b;
I tried creating an update query from the above and got a Property Not Found error.
I tried creating an update query from only one of the above selects and again got a Property Not Found error. That query is:
I'm not sure what the WHERE clause should contain so that the new field values are in the right ID/BarDate record, and not clear how to get the subquery to operate properly.Code:UPDATE VIX_RiskZ SET AvgSMA30_10 = Round((SELECT ID, AVG(SMA30_10) from VIX_RiskZ where ID BETWEEN b.ID and b.ID-299 FROM VIX_RiskZ AS b), 2) WHERE ID = ID
Also looked at:
https://www.access-programmers.co.uk/forums/threads/using-select-as-a-subquery-within-update-query.280714/
And tried:
UPDATE VIX_RiskZ, Round((SELECT AVG(SMA30_10) from VIX_RiskZ where ID BETWEEN b.ID and b.ID-299 FROM VIX_RiskZ AS b), 2) AS AvgSMA300 SET AvgSMA30_10 = AvgSMA300
WHERE ID = ID
And still get Property not found.
Thanks,
Eric