Joining two temp tables and making calculations within them to find price elasticity

70 views Asked by At

I'm trying to calculate price elasticity in product level, where I have to find Δprice/Δvolume for elasticity calculations. We have a weekly aggregated sales data with start and end date of each week. I know this is not the optimal solution but I try to create temp tables and then join them week over week to find Δprice/Δvolume, from the table:

sales2022YTD TABLE Example

with the code:

with X as 
(SELECT DATE_FROM, PRODUCT_NAME, VOLUME as volume1, NET_SALES/VOLUME as netprice1
FROM sales2022YTD
WHERE DATE_FROM = '2022-01-03'),

Y as
(SELECT DATE_FROM, PRODUCT_NAME, VOLUME as volume2, NET_SALES/VOLUME as netprice2
FROM sales2022YTD
WHERE DATE_FROM = '2022-08-03')

SELECT netprice2/netprice1 as pricediff, volume2/volume1 as volumediff
FROM Y as y1
LEFT JOIN X as x1
ON y1.PRODUCT_NAME = x1.PRODUCT_NAME
WHERE x1.PRODUCT_NAME = y1.PRODUCT_NAME

So basically I want to merge the two temp tables on the common product names and see weekly price and volume differences. With this query, I get only pricediff and volumediff columns without any value. I also would like to note that I have common product names in the two seperate weeks.

As a further step, I will extend the code to 52 weeks to calculate weekly elasticity. Any easier/less bulkier approach would be really appreciated.

Much thanks!!

0

There are 0 answers