You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BigQuery SQL Script to get the rolling and cumulative percentage change for the Average Housing Price by State
WITH PRICES AS (
SELECTDate
,State
,Residential_Dwelling_Average_Value_AUD AS AVERAGE_HOUSING_PRICE
,LAG(Residential_Dwelling_Average_Value_AUD) OVER (PARTITION BY State ORDER BYDateASC) AS LAG_AVERAGE_HOUSING_PRICE
,ROW_NUMBER() OVER (PARTITION BY State ORDER BYDateASC) AS RNK
FROMtransformation.ABS_DWELLING_DATA_TRF
)
,ANCHOR_PRICE AS (
SELECTDate
,State
,AVERAGE_HOUSING_PRICE AS ANCHOR_PRICE
FROM PRICES
WHERE RNK =1
)
SELECTP.Date
,P.State
,P.AVERAGE_HOUSING_PRICE
,A.ANCHOR_PRICE
,P.LAG_AVERAGE_HOUSING_PRICE
,ROUND((P.AVERAGE_HOUSING_PRICE-P.LAG_AVERAGE_HOUSING_PRICE)/P.LAG_AVERAGE_HOUSING_PRICE, 2) AS PERCENT_CHANGE
,ROUND((P.AVERAGE_HOUSING_PRICE-A.ANCHOR_PRICE)/A.ANCHOR_PRICE, 2) AS CUMULATIVE_PERCENT_CHANGE
FROM PRICES P
LEFT JOIN ANCHOR_PRICE A
ONP.State=A.StateORDER BY State, DateASC
;