I have been struggling for a few days now on a way to calculate MRR for the table as follows :
| ID | ActualEndDate | CreatedAt | PlanType | Price |
|---|---|---|---|---|
| ABC | 2023-06-09 | 2022-06-10 | Annual | 110 |
| CFR | 2022-08-11 | 2022-06-12 | Mensual | 12 |
| CFR | 2022-08-15 | 2022-07-15 | Mensual | 12 |
ActualEndDate : when the subscription is stopping at the moment
CreatedAt : when the subscription has started
PanType : type of subscription
Price : price of subscription
Monthly price : price of subscription per month
In my case i would like to calculate the MRR as follows :
The annual price should be counted each month (with the monthly price) from the CreatedAt to the ActualEndDate. The mensual price should be counted on the month it’s CreatedAt and then till the ActualEndDate.
I guess this is doable with CTE, but i did not find a good way to do it for now.
In my case i woul like a result as follows :
| Month | MRR |
|---|---|
| 2022-06 | 23 |
| 2022-07 | 35 |
| 2022-08 | 35 |
Thank you all !