Salesforce Formula (Modified Feb 3rd, 2024):
/* 1) Calculate the target Year and Month parts */
IF(
/* We do an IF just to name these sub-calculations more clearly. */
false,
DATE(1900,1,1),
/* The final DATE() is below; this IF(false) is a trick to store sub-expressions in Flow if needed. */
DATE(
/* ---- YEAR part ---- */
YEAR(Contract_Start_Date__c)
+ FLOOR(
( MONTH(Contract_Start_Date__c) + Contract_Term__c - 1 )
/ 12
),
/* ---- MONTH part ---- */
MOD(
MONTH(Contract_Start_Date__c) + Contract_Term__c - 1,
12
) + 1,
/* ---- DAY part (capped to last valid day) ---- */
MIN(
DAY(Contract_Start_Date__c),
DAY(
/* "Last day of target month" = DATE(..., M+1,1) - 1 */
DATE(
/* Possibly bump the year if M = 12 */
YEAR(Contract_Start_Date__c)
+ FLOOR(
( MONTH(Contract_Start_Date__c) + Contract_Term__c - 1 )
/ 12
)
+ IF(
MOD(
MONTH(Contract_Start_Date__c) + Contract_Term__c - 1,
12
) + 1 = 12,
1,
0
),
/* If month is 12, next month is 1; else just M + 1 */
IF(
MOD(
MONTH(Contract_Start_Date__c) + Contract_Term__c - 1,
12
) + 1 = 12,
1,
MOD(
MONTH(Contract_Start_Date__c)
+ Contract_Term__c - 1,
12
) + 2
),
1
)
- 1
)
)
)
)
- 1