Business Context and Problem statement
I am building a simple canvas app which tracks all my recurring payments. The app would send out a notification when the next recurring date arrives. The problem is to calculate the next due date.
Current Setup
Canvas app has a form component backed by a SharePoint list. There are three parameters that I accept in the configuration
- Start Date - when was the subscription started
- Category - defines what the interval is; possible values - Month, Year, Day
- Interval - the actual recurrence interval; eg - every 1 Month or 2 Year or 10 Day, etc.

I am unfortunately having a hard time wrapping my head around it. So far, following is the code that I have in place to calculate next due date. This obviously does not work as expected.
If(
And(
!IsBlank(StartDate),
!IsBlank(Frequency),
!IsBlank(Interval)
),
Switch(
Frequency,
"Month",
DateAdd(
StartDate,
RoundUp(
Mod(
If(
DateDiff(StartDate,Today(),Months) > 0,
DateDiff(StartDate,Today(),Months),
1
)
,12
) / Interval,
0
) * Interval,
Months
)
)
)
Any pointers would be greatly appreciated.