I am trying to calculate the sales volume difference between a given month and the same month one year back (e.g Jan 2021 - Jan 2020). The tricky part is that it should be done on customer level. My table now looks like this:
| Date | Customer_number | Sales_Volume |
|---|---|---|
| 14.01.2020 | 1111 | 1000 |
| 13.01.2020 | 2222 | 2000 |
| 21.02.2020 | 1111 | 4000 |
| 17.02.2020 | 2222 | 5000 |
| 22.01.2021 | 1111 | 1500 |
| 24.01.2021 | 2222 | 2600 |
| 19.02.2021 | 1111 | 4700 |
| 18.02.2021 | 2222 | 5800 |
And my output should look like this:
| Date | Customer_number | Sales_Volume | Volume_Difference |
|---|---|---|---|
| 14.01.2020 | 1111 | 1000 | 0 |
| 13.01.2020 | 2222 | 2000 | 0 |
| 21.02.2020 | 1111 | 4000 | 0 |
| 17.02.2020 | 2222 | 5000 | 0 |
| 22.01.2021 | 1111 | 1500 | 500 |
| 24.01.2021 | 2222 | 2600 | 600 |
| 19.02.2021 | 1111 | 4700 | 700 |
| 18.02.2021 | 2222 | 5800 | 800 |

