Sales Reporting using LAG function
576705May 10 2007 — edited May 11 2007Hello,
I have an existing report that shows the revenue, quantity and average price of each product sold by customer. The information is shown for invoices that were generated during a selected period. To establish the invoice date range, there is a parameter for the begin date and the end date.
In addition to the existing information, I would like to provide the revenue, quantity and average price for the prior year (PY). If the end user enters 15-JAN-06 as the begin date and 28-JAN-06 as the end date, I would like to show the revenue, quantity and average price in the PY columns for 15-JAN-05 through 28-JAN-05. For example:
Customer – Item – Rev – Qty – Avg – PY Rev – PY Qty – PY Avg
Joe’s – 123 - $1000 – 100 - $10 - $2000 – 200 - $10
Joe’s – 456 - $100 – 10 - $10 – null – null – null
Joe’s – 789 – null – null – null - $3000 – 300 - $10
I’ve been playing with the LAG function, but haven’t had any luck. Is this the appropriate function? If so, what would be the best way to use it?
Any suggestions will be appreciated. I am very new to using analytic functions.
Thanks,
Angela