Modifying formula / adding dependency

Hello,

I added a formula to one of our custom fields that calculates any new ARR on an opportunity and revenue line item (especially usefully for renewals with upsells):

ifElse(contains($arr_yes_no_c,"Y"),subtract($discount_price,$renewal_arr_c),"")

However I would like to add one more condition (or exception) to this formula. In case of Renewals (NOT Renewals with upsells) that have a contraction (Year 1 ARR = 10,000 USD / Year 2 ARR = 5,000 USD) I would like the new ARR to be 0 - right now it's negative. 

So is there a way to modify this formula so that it excludes Renewals (Renewals are chosen from another custom field - Opportunity type) or is there a dependency that I can add that will say only calculate New ARR for New Business, Upsells and Renewals with Upsell types?

Thank you!

Parents
  • ,

    If this scenario is the only scenario in which the ARR would be negative, you can modify the formula to account for that scenario:

    ifElse(contains($arr_yes_no_c,"Y"),ifElse(greaterThan(subtract($discount_price,$renewal_arr_c),0),subtract($discount_price,$renewal_arr_c),"0"),"")

  • Hi Chris, 

    I tried that, however it's not returning any values now for New ARR. 

    I was wondering - can I add to my formula a condition that will exclude Opportunity type - renewal?:

    ifElse(contains($arr_yes_no_c,"Y"),subtract($discount_price,$renewal_arr_c),"") - would that be the rollupConditionalSum function? How can I exclude (rather than include values?) 

    For my Opportunity type I have: New Business, Upsell, Renewal with Upsell, Renewal, Additional Services - I would like to exclude Renewal and Additional Services

    Thanks for your help!

  • Hi ,

    That's odd that the formula is not returning results for you. I created the same fields on the Revenue Line Items module and confirmed that the calculation works as expected:

    If you would prefer to just use the rollupCoditionalSum formula at the opportunity level, I recommend the following steps:

    1. Create a currency field (e.g. new_arr_c) on the RLI module that calculates the potential new ARR with your given calculation:
      subtract($discount_price,$renewal_arr_c)
    2. Create a text field (e.g. count_arr_c) on the RLI module to flag whether it should be counted in the opportunity calculation
    3. Set a formula in the field to flag it when one of the desired types is set on the RLI record:
      ifElse(isInList($product_type,createList("New Business","Upsell","Renewal with Upsell")),"Yes","No")
    4. On the Opportunity module create a currency field (if you already haven't) with the following formula to only pull in the values from the desired RLI types:
      rollupConditionalSum($revenuelineitems,"new_arr_c", "count_arr_c", "Yes")

    Once you add the fields, you will need to recalculate values on any existing RLIs to properly report up the information to their corresponding opportunities. 

  • Hi Chris, 

    Interesting results - maybe we are not fully aligned. Is it possible that my results for NEW ARR are 0 because Type (e.g. New Business) I have this field on the Opportunity Layout, not on the RLI layout? 

  • Hi Chris, 

    Yes you are absolutely right - thank you very much for your help, that's a big milestone for us. 

    I have just one follow up question regarding discounts. 

    Right now, I can see that there is a field to insert discount in percentage. Is there another standard field to put discount as currency that is already pre-build it Sugar? I cannot seem to find it?

  • Hi ,

    The field where you can enter a discount percentage also supports putting in flat currency amounts as well. Click the percent sign to toggle between the two options:

  • Hi Chris, 

    Thanks yes I was able to figure it out, that's very useful.

    I began to move the data from my old fields to new ones and I stumbled upon a conversion (?) problem. 

    When inputting Unit Price, Service Duration (e.g. 24 months - I replaced service duration with Quantity to calculate Calculated Amount) in USD (it's my base currency) I receive correct results. 

    However, when I input e.g. Unit Price 200,000 EUR and Service Duration 36months, my calculated amount is 584,000 EUR instead of 600,000 EUR. 

    Are there any steps of fields I need to use for the conversion?

  • Hi Ada,

    Please clarify a few things for me to better understand the issue:

    1. What is the current formula you are using for the total_amount field on the RLI module?
    2. What currency is flagged as your system default currency under Admin > Currencies?
  • Hi Chris, 

    This the formula: 

    ifElse(and(isNumeric($quantity), isNumeric($discount_price)),
    ifElse(equal($quantity, 0),
    $total_amount,
    currencySubtract(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    ifElse(equal($discount_select, "1"),
    currencyMultiply(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    currencyDivide($discount_amount, 100)
    ),
    ifElse(greaterThan($quantity, 0),
    ifElse(isNumeric(toString($discount_amount)),
    ifElse(greaterThan(0, $discount_price),
    negate($discount_amount), $discount_amount
    ), 0
    ),
    ifElse(isNumeric(toString($discount_amount)), negate($discount_amount), 0))
    )
    )
    ), ""
    )

  • Hi Ada,

    I may be misunderstanding something then from your prior post. I took your post to mean that you getting the Calculated Amount (total_amount) value by doing the following:

    1. Figuring out the per month price of the Unit Cost (e.g. $200,000 / 12)
    2. Multiplying that per month price by the service duration

    However, the formula you shared for total_amount appears to be the default formula. Do you have another field performing the calculation where it is showing the 584k Euro amount? If so, what formula are you using there?

  • Hi Chris, 

    This is everything I am using to get NewARR: 

    1. Unit Price

    ifElse(
    and(
    equal($product_template_id, ""),
    not(isNumeric($discount_price)),
    not(equal($quantity, 0))
    ),
    divide($likely_case, $quantity),
    $discount_price
    )

    2. Service (tick box), Subscription Start Date, Service Duration 

    --> QQ on this: is it possible to change Service Duration by default to 12 months?

    3. Calculated Amount

    ifElse(and(isNumeric($quantity), isNumeric($discount_price)),
    ifElse(equal($quantity, 0),
    $total_amount,
    currencySubtract(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    ifElse(equal($discount_select, "1"),
    currencyMultiply(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    currencyDivide($discount_amount, 100)
    ),
    ifElse(greaterThan($quantity, 0),
    ifElse(isNumeric(toString($discount_amount)),
    ifElse(greaterThan(0, $discount_price),
    negate($discount_amount), $discount_amount
    ), 0
    ),
    ifElse(isNumeric(toString($discount_amount)), negate($discount_amount), 0))
    )
    )
    ), ""
    )

    4. NewARR

    ifElse(contains($arr_yes_no_c,"Y"),ifElse(greaterThan(subtract($discount_price,$renewal_arr_c),0),subtract($discount_price,$renewal_arr_c),"0"),"")

    I am testing this once more to see the currencies.

  • I was always wondering why writing no-code formulas is sometimes a topic starter in the developers' branch of the Club - DevClub - also I found people sometimes call writing formulas for Cal Fields "coding a formula".

    Meeting the formula like above makes it clearer why - we can imagine how much time and effort it takes to write and validate implementation -  I do admire the great persistency of Sugar Admins in getting such monsters to work!

    As for me, this is clearly the case that shows what trying to put more-or-less complex calculation logic into the single Calc Field may lead to - IMHO, even if to be lucky enough to configure "superformula" once, the Prefix (Polish) Notation of the Calc Fields may turn the result into hardly readable and non-easy understandable ...code?.

    I know people that were facing the same challenge of implementing calculation logic for Sugar and they never regret employing other no-code techniques for setting up automation in Sugar - the OOTB SugarBPM to visualize workflows automation, and Logic Builder service to regularly draw and redraw calculations, set up and adjust algorithms implementations

    I hope this makes sense

    Best Regards,
    Dmytro Chupylka

    integroscrm.com
    We make work in Sugar CRM system faster, more convenient and efficient



  • To be honest, I am quite surprise on how SugarCRM approached calculated fields and formulas - almost as low-coding.

    Also, I noticed that some out-of-the-box fields from SugarCRM are low-coded.

    My experience with other CRM systems is much different, where a formula is a formula and has nothing to do with coding.

    Anyway, I hope I am good for now with calculated fields :D

  • I spotted the issue - it's not currency exchange issue, it's an issue with Calculated Amount field - strange, considering that it's an out-of-the box field: 

    ifElse(and(isNumeric($quantity), isNumeric($discount_price)),
    ifElse(equal($quantity, 0),
    $total_amount,
    currencySubtract(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    ifElse(equal($discount_select, "1"),
    currencyMultiply(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    currencyDivide($discount_amount, 100)
    ),
    ifElse(greaterThan($quantity, 0),
    ifElse(isNumeric(toString($discount_amount)),
    ifElse(greaterThan(0, $discount_price),
    negate($discount_amount), $discount_amount
    ), 0
    ),
    ifElse(isNumeric(toString($discount_amount)), negate($discount_amount), 0))
    )
    )
    ), ""
    )

    And this is the formula to multiply for the Number of Months of the contract:

    multiply(add(subtract(monthofyear($service_end_date),monthofyear($service_start_date)),multiply(subtract(year($service_end_date),year($service_start_date)),12)),0.083333333)

    --> this is working in most cases, just on some opps is off.

    What's more strange, is that the field seems to work on-and-off. On some of my opportunities it works 100% and on some it does not calculate the Calculated Amount correctly.

    Example - correctly calculated (for privacy I hid the product name):

    Example - incorrectly calculated:

    Any idea why is that occurring only on some opps? Both New Business and Upsell?

    Thanks!

Reply
  • I spotted the issue - it's not currency exchange issue, it's an issue with Calculated Amount field - strange, considering that it's an out-of-the box field: 

    ifElse(and(isNumeric($quantity), isNumeric($discount_price)),
    ifElse(equal($quantity, 0),
    $total_amount,
    currencySubtract(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    ifElse(equal($discount_select, "1"),
    currencyMultiply(
    ifElse(isNumeric($subtotal), $subtotal, multiply($discount_price, $quantity)),
    currencyDivide($discount_amount, 100)
    ),
    ifElse(greaterThan($quantity, 0),
    ifElse(isNumeric(toString($discount_amount)),
    ifElse(greaterThan(0, $discount_price),
    negate($discount_amount), $discount_amount
    ), 0
    ),
    ifElse(isNumeric(toString($discount_amount)), negate($discount_amount), 0))
    )
    )
    ), ""
    )

    And this is the formula to multiply for the Number of Months of the contract:

    multiply(add(subtract(monthofyear($service_end_date),monthofyear($service_start_date)),multiply(subtract(year($service_end_date),year($service_start_date)),12)),0.083333333)

    --> this is working in most cases, just on some opps is off.

    What's more strange, is that the field seems to work on-and-off. On some of my opportunities it works 100% and on some it does not calculate the Calculated Amount correctly.

    Example - correctly calculated (for privacy I hid the product name):

    Example - incorrectly calculated:

    Any idea why is that occurring only on some opps? Both New Business and Upsell?

    Thanks!

Children
No Data