Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dhw
Constraint Violating Yak Guru
332 Posts |
Posted - 2010-04-19 : 14:49:08
|
Hi all -I am trying to figure out how I can calculate the the percentage difference (could be positive or negative) from one week's value as compared to the previous week. So far, I am not having any luck in getting this solved.My table and some sample data is like:CustomerCode WeekLabel WeekDate Amount PctDiffABC1234 Week0 2009-02-05 425.00 ABC1234 Week1 2009-02-12 525.00 ABC1234 Week2 2009-02-19 375.00 ABC1234 Week3 2009-02-26 408.00 ABC1234 Week4 2009-03-05 487.00 ABC1234 Week5 2009-03-12 471.00 ABC1234 Week6 2009-03-19 512.00 For the first week (Week0), there doesn't need to be a PctDiff value. But I am trying to compute the PctDiff for Week1 - Week6 and show the percentage increase or decrease for the current week, based on the previous week. So, for the above example, the PctDiff column would be something like 23.6% (or 0.236, however I want to format it).Any thoughts or suggestions will be welcome and appreciated.Thanks, - will |
|
|
dhw
Constraint Violating Yak Guru
332 Posts |
Posted - 2010-04-19 : 15:31:49
|
| Hi allGot this resolved. Using a self JOIN and it works great and provides the results I was looking for.thanks |
 |
|
|
|
|
|