{"id":805,"date":"2021-03-02T15:44:27","date_gmt":"2021-03-02T15:44:27","guid":{"rendered":"http:\/\/morecpq.com\/?p=805"},"modified":"2022-09-28T17:45:16","modified_gmt":"2022-09-28T17:45:16","slug":"cpq-price-rule-calculate-end-date","status":"publish","type":"post","link":"https:\/\/morecpq.com\/index.php\/2021\/03\/02\/cpq-price-rule-calculate-end-date\/","title":{"rendered":"CPQ &#8211; Price Rule &#8211; Add Months to Any Date (ADDMONTHS formula function)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"792\" height=\"46\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-Quote-Salesforce-6.png?resize=792%2C46&#038;ssl=1\" alt=\"\" class=\"wp-image-2121\" srcset=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-Quote-Salesforce-6.png?w=792&amp;ssl=1 792w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-Quote-Salesforce-6.png?resize=300%2C17&amp;ssl=1 300w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-Quote-Salesforce-6.png?resize=768%2C45&amp;ssl=1 768w\" sizes=\"(max-width: 792px) 100vw, 792px\" \/><\/figure>\n\n\n\n<p><strong>Alternate Formula<\/strong><\/p>\n\n\n\n<p>Here&#8217;s a formula to put in a Price Action to add months to any Date.  You can use this in lieu of the ADDMONTHS() function which is not supported in Price Action formula. <\/p>\n\n\n\n<p>Note: Leap year is calculated by: IF(( MOD(YEAR(Date_Field__c),4) == 0 &amp;&amp; (MOD(YEAR(Date_Field__c),100) != 0 || MOD(YEAR(Date_Field__c),400) == 0) ), 29, 28)<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:12px\"><code>DATE(\nYEAR( Date_Field__c ) + FLOOR( ( MONTH ( Date_Field__c ) + Months_to_Add__c - 1 ) \/ 12 ),\nMOD( MONTH ( Date_Field__c ) + Months_to_Add__c - 1 +\nIF( DAY ( Date_Field__c ) &gt; CASE( MOD( MONTH( Date_Field__c ) + Months_to_Add__c - 1, 12 ) + 1,\n2, IF(( MOD(YEAR(Date_Field__c),4) == 0 &amp;&amp; (MOD(YEAR(Date_Field__c),100) != 0 || MOD(YEAR(Date_Field__c),400) == 0) ), 29, 28),\n4, 30,\n6, 30,\n9, 30,\n11, 30,\n31 ), 1, 0 ), 12 ) + 1,\nIF( DAY( Date_Field__c ) &gt; CASE( MOD( MONTH( Date_Field__c ) + Months_to_Add__c - 1, 12 ) + 1,\n2, IF(( MOD(YEAR(Date_Field__c),4) == 0 &amp;&amp; (MOD(YEAR(Date_Field__c),100) != 0 || MOD(YEAR(Date_Field__c),400) == 0) ), 29, 28),\n4, 30,\n6, 30,\n9, 30,\n11, 30,\n31 ),\n1, DAY( Date_Field__c )\n)\n)<\/code><\/pre>\n\n\n\n<p>Edit: Many people have asked about the solution for calculating End Date when given Start Date and Subscription Term.  It is below!<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:12px\"><code>DATE(\nYEAR( SBQQ__StartDate__c ) + FLOOR( ( MONTH ( SBQQ__StartDate__c ) + SBQQ__SubscriptionTerm__c - 1 ) \/ 12 ),\nMOD( MONTH ( SBQQ__StartDate__c ) + SBQQ__SubscriptionTerm__c - 1 +\nIF( DAY ( SBQQ__StartDate__c ) &gt; CASE( MOD( MONTH( SBQQ__StartDate__c ) + SBQQ__SubscriptionTerm__c - 1, 12 ) + 1,\n2, IF(( MOD(YEAR(SBQQ__StartDate__c),4) == 0 &amp;&amp; (MOD(YEAR(SBQQ__StartDate__c),100) != 0 || MOD(YEAR(SBQQ__StartDate__c),400) == 0) ), 29, 28),\n4, 30,\n6, 30,\n9, 30,\n11, 30,\n31 ), 1, 0 ), 12 ) + 1,\nIF( DAY( SBQQ__StartDate__c ) &gt; CASE( MOD( MONTH( SBQQ__StartDate__c ) + SBQQ__SubscriptionTerm__c - 1, 12 ) + 1,\n2, IF(( MOD(YEAR(SBQQ__StartDate__c),4) == 0 &amp;&amp; (MOD(YEAR(SBQQ__StartDate__c),100) != 0 || MOD(YEAR(SBQQ__StartDate__c),400) == 0) ), 29, 28),\n4, 30,\n6, 30,\n9, 30,\n11, 30,\n31 ),\n1, DAY( SBQQ__StartDate__c )\n)\n)-1<\/code><\/pre>\n\n\n\n<p><strong>MoreCPQ App<\/strong><\/p>\n\n\n\n<p>In our MoreCPQ app, we include functionality you can install in your org that adds the ADDMONTHS function to your Price Rules!  It also has a page that will convert ADDMONTHS formulas for you in the event you don&#8217;t want automation\/new fields in the org.  See screenshots below!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"928\" height=\"860\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-CPQ-Add-ADDMONTHS-to-Price-Rule-Formulas-Salesforce-2.png?resize=928%2C860&#038;ssl=1\" alt=\"\" class=\"wp-image-2089\" srcset=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-CPQ-Add-ADDMONTHS-to-Price-Rule-Formulas-Salesforce-2.png?w=928&amp;ssl=1 928w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-CPQ-Add-ADDMONTHS-to-Price-Rule-Formulas-Salesforce-2.png?resize=300%2C278&amp;ssl=1 300w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-CPQ-Add-ADDMONTHS-to-Price-Rule-Formulas-Salesforce-2.png?resize=768%2C712&amp;ssl=1 768w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/figure>\n\n\n\n<p>The first formula (new custom field) is converted to the second formula (actual SBQQ field) via automation (After Update Trigger on Price Action).  The same goes for the Price Condition formula fields.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"940\" height=\"540\" src=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-0-Salesforce-4.png?resize=940%2C540&#038;ssl=1\" alt=\"\" class=\"wp-image-2091\" srcset=\"https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-0-Salesforce-4.png?resize=1024%2C588&amp;ssl=1 1024w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-0-Salesforce-4.png?resize=300%2C172&amp;ssl=1 300w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-0-Salesforce-4.png?resize=768%2C441&amp;ssl=1 768w, https:\/\/i0.wp.com\/morecpq.com\/wp-content\/uploads\/2022\/09\/Snip-0-Salesforce-4.png?w=1078&amp;ssl=1 1078w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p><strong>MoreCPQ App Installer<\/strong><\/p>\n\n\n\n<p>Installer is in <a href=\"https:\/\/morecpq.com\/index.php\/2022\/09\/22\/the-morecpq-app\/\" target=\"_blank\" rel=\"noreferrer noopener\">this article<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Alternate Formula Here&#8217;s a formula to put in a Price Action to add months to any Date. You can use this in lieu of the ADDMONTHS() function which is not supported in Price Action formula. Note: Leap year is calculated by: IF(( MOD(YEAR(Date_Field__c),4) == 0 &amp;&amp; (MOD(YEAR(Date_Field__c),100) != 0 || MOD(YEAR(Date_Field__c),400) == 0) ), 29, &hellip;<br \/><a href=\"https:\/\/morecpq.com\/index.php\/2021\/03\/02\/cpq-price-rule-calculate-end-date\/\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\">Continue reading <span class=\"screen-reader-text\">CPQ &#8211; Price Rule &#8211; Add Months to Any Date (ADDMONTHS formula function)<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-805","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/comments?post=805"}],"version-history":[{"count":14,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/805\/revisions"}],"predecessor-version":[{"id":2128,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/posts\/805\/revisions\/2128"}],"wp:attachment":[{"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/media?parent=805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/categories?post=805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/morecpq.com\/index.php\/wp-json\/wp\/v2\/tags?post=805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}