I don't know if it's possible if I could do this:
I have this table:
| Customer | Week | SoldUnits |
|---|---|---|
| C1 | 1 | 24 |
| C1 | 2 | 17 |
| C1 | 3 | 52 |
| C2 | 1 | 18 |
| C2 | 2 | 65 |
| C2 | 3 | 12 |
| C2 | 4 | 33 |
| C3 | 1 | 18 |
| C3 | 2 | 65 |
And I want to calculate the average of the last 2 weeks available of every customer. For example, I have to return this table:
| Customer | AverageSoldUnits |
|---|---|
| C1 | 34.5 |
| C2 | 22.5 |
| C3 | 41.5 |
The trick is that not every customer has the same max Week.