Service Duration field name for formula?

Hello, 

I have a custom formula in SugarCRM that calculates New Annual Recurring Revenue:

ifElse( 

equal($arr_yes_no_c,"Yes") 

,ifElse( 

equal($product_type,"Renewal") 

,0 

,ifElse( 

equal($product_type,"Renewal_with_upsell") 

,subtract($discount_price,$renewal_arr_c) 

,ifElse( 

greaterThan(subtract($discount_price,$renewal_arr_c),0) 

,subtract($discount_price,$renewal_arr_c) 

,0 

) 

) 

) 

,0 

) 

I would like to modify, to add another condition. However, this condition includes Service Duration Unit - I cannot find a field name for it, do you know where can I find the Field Name (not Display Label) for it? 

Parents Reply Children
  • Hi  ,

    It's definitely possible! When comparing two date fields and calculating the difference in Sugar, you need to account for 3 scenarios:

    1. start date is today or in the future and end date is in the future
    2. start date is in the past and end date is in the past or today
    3. start date is in the past and end date is in the future

    The following formula accounts for those 3 scenarios:

    ifElse(
        or(
            greaterThan(
                daysUntil($service_start_date),
                -1
            ),
            not(
                greaterThan(
                    daysUntil($service_end_date),
                    0
                )
            )
        ),
        abs(
            subtract(
                abs(
                    daysUntil($service_end_date)
                ),
                abs(
                    daysUntil($service_start_date)
                )
            )
        ),
        subtract(
            daysUntil($service_end_date),
            daysUntil($service_start_date)
        )
    )

    The first part of the ifElse does the same formula as long as the dates fall under scenario 1 or 2 above. Scenario 3 is executed in the last calculation.

    One note is that the value returned by this formula is 1 less than the actual number of days. For instance, with 2024 being a leap year, the days between November 9, 2023 and November 9, 2024 should be 366, but the formula returns 365. Similarly, when calculating days of a monthly service duration like September 15th to October 15th, the result is 29 instead of 30. You can use the add() formula around two calculations to increment the value by 1 if that is important for your use case.

    Chris