I have a sample of a table as below:
Customer Ref | Bear Rate | Distance | Month | Revenue |
---|---|---|---|---|
ABA-IFNL-001 | 1000 | 01/01/2022 | -135 | |
ABA-IFNL-001 | 1000 | 01/02/2022 | -135 | |
ABA-IFNL-001 | 1000 | 01/03/2022 | -135 | |
ABA-IFNL-001 | 1000 | 01/04/2022 | -135 | |
ABA-IFNL-001 | 1000 | 01/05/2022 | -135 | |
ABA-IFNL-001 | 1000 | 01/06/2022 | -135 |
I also have a sample of a calendar table as below:
Date | Year | Week | Quarter | WeekDay | Qtr Start | Qtr End | Week Day |
---|---|---|---|---|---|---|---|
04/11/2022 | 2022 | 45 | 4 | Fri | 30/09/2022 | 29/12/2022 | 1 |
05/11/2022 | 2022 | 45 | 4 | Sat | 30/09/2022 | 29/12/2022 | 2 |
06/11/2022 | 2022 | 45 | 4 | Sun | 30/09/2022 | 29/12/2022 | 3 |
07/11/2022 | 2022 | 45 | 4 | Mon | 30/09/2022 | 29/12/2022 | 4 |
08/11/2022 | 2022 | 45 | 4 | Tue | 30/09/2022 | 29/12/2022 | 5 |
09/11/2022 | 2022 | 45 | 4 | Wed | 30/09/2022 | 29/12/2022 | 6 |
10/11/2022 | 2022 | 45 | 4 | Thu | 30/09/2022 | 29/12/2022 | 7 |
11/11/2022 | 2022 | 46 | 4 | Fri | 30/09/2022 | 29/12/2022 | 1 |
12/11/2022 | 2022 | 46 | 4 | Sat | 30/09/2022 | 29/12/2022 | 2 |
13/11/2022 | 2022 | 46 | 4 | Sun | 30/09/2022 | 29/12/2022 | 3 |
14/11/2022 | 2022 | 46 | 4 | Mon | 30/09/2022 | 29/12/2022 | 4 |
15/11/2022 | 2022 | 46 | 4 | Tue | 30/09/2022 | 29/12/2022 | 5 |
16/11/2022 | 2022 | 46 | 4 | Wed | 30/09/2022 | 29/12/2022 | 6 |
17/11/2022 | 2022 | 46 | 4 | Thu | 30/09/2022 | 29/12/2022 | 7 |
How can I join/link the tables to report on revenue over weekly and quarterly periods using the calendar table? I can put into two tables if needed as an output eg:
Quarter Starting | 31/12/2021 | 01/04/2022 | 01/07/2022 | 30/09/2022 |
---|---|---|---|---|
Quarter | 1 | 2 | 3 | 4 |
Revenue | 500 | 400 | 540 | 540 |
Week Date Start | 31/12/2021 | 07/01/2022 | 14/01/2022 | 21/01/2022 |
---|---|---|---|---|
Week | 41 | 42 | 43 | 44 |
Revenue | 33.75 | 33.75 | 33.75 | 33.75 |
I am using alteryx for this but wouldnt mind explaination of possible logic in sql to apply it into the system Thanks