function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lisa Lee-BanksLisa Lee-Banks 

Need the correct formula field syntax for IF

I'm trying to create a formula field for loan anniversary date which is determined by the renewal date and the term of the loan (number field). If the term of the loan is 5 years then the 4 year anniversary date is the renewal date - 365 days.

Currently I have this syntax but there's a syntax error:
IF(
(Term__c) = 5),
(Renewal_Date__c) - 365
)
VinayVinay (Salesforce Developers) 
Hi Lisa,

What is the error that you see?

Thanks,
Lisa Lee-BanksLisa Lee-Banks
Error: Syntax error. Extra ','
Andrew GAndrew G
remember that an if need 3 arguments IF( boolean test, true value, false value)
Similarly, what sort of field is Term__c?
This would work if Term is a number field.
IF(
    Term__c = 5,
    Renewal_Date__c - 365,
    Renewal_Date__c
)
If a picklist
IF(
    TEXT(Term__c) = '5',
    Renewal_Date__c - 365,
    Renewal_Date__c
)
If you are wanting multiple options, rather than a nested IF when you are just checking the Term field, you could use CASE
CASE( TEXT(Term__c),
  5,Renewal_Date__c - 365,
  4,Renewal_Date__c - 365,
  3,Renewal_Date__c - 180,
  2,Renewal_Date__c - 90,
  1,Renewal_Date__c - 60,
  Renewal_Date__c
)
regards
Andrew
Lisa Lee-BanksLisa Lee-Banks
Thanks for the case syntax this works perfectly.
Andrew GAndrew G
No worries.  If one of the answers resolved your issue, please select as best answer so that the request can be marked solved.  In this manner it can help other subscribers in the forums, and I can save a little time by not checking it everyday to see it requires further input.  ;-)

Have a great day
Andrew