Hello Community,
So my table is a list of orders with a start date and end date such as the one below (the dates are in MM/DD/YYYY format).
ORDER_ID START_DATE END_DATE
1 11/1/2016 11/28/2017
2 11/2/2016 11/29/2017
3 12/1/2016 12/29/2017
4 12/2 2016 12/30/2017
I need an output which displays a count of customers who are active in each month, the table below shows what the result should be. So esentially I need an output with "MONTH" and "Count of Active Orders".
Explaining via an example would be easier so for the OUTPUT and the month of "Nov 2016", we would consider active every ORDER_ID which has a START_DATE of less than or equal to the end of the MONTH, so in this case START_DATE<=Nov 30th 2016 AND has an END_DATE greater than the end of the current MONTH, so in this case END_DATE>Nov 30th 2016.
I already created a seperate date table and have tried creating a number of different things but cannot seem to get the numbers right. This was of course only a sample of the data, the real data being thousands of orders
OUTPUT FORMAT
MONTH COUNT OF ACTIVE ORDERS
Oct 2016 0
Nov 2016 2
Dec 2016 4
Jan 2017 4
...
Nov 2017 4
Dec 2017 2
Jan 2018 0
Any help would be really appreciated.
Moiz