Hi all. I have a complicated problem regarding the sums of relevant values in different periods that needs to be solved but not sure how.
The simplified situation is like this:-
I have a table A with following fields:
Year, Month, Stock, Price.
Let's say from table A I have data from Year 2008 to 2011 with each year having 100 of different stocks with different prices each month.
With above data fields, I need to create a dataset B with the following fields:
Year, Month, Stock, Current_MTD_Price_Sum, Previous_MTD_Price_Sum, Current_YTD_Price_Sum, Previous_YTD_Price_Sum.
The Current_MTD_Price_Sum is the sum of prices of each stock from that month itself while Previous_MTD_Price_Sum refers to the price sum of the same stock in a year before.
Eg. If the year is 2009 and the month is April, the Current_MTD_Price_Sum would refer to the sum of prices of that stock Z in April 2009 while Previous_MTD_Price_Sum would show the sum of prices for April 2008 for the same stock Z.
Meanwhile, Current_YTD_Price_Sum would show the total sum for the stock from January to April 2010 if the current month is April and Current Year is 2010. Previous_YTD_Price_Sum would be the sum of prices for the stock from January to April 2009.
I have tried to use retain and sum statements but they can only add to a certain period. The tables may look simple but the process to get the correct values has been a great challenge for me so far.
Thanks for your time.
KYW