Examples of Advanced Formula Fields
Use the following formula samples when creating custom formula fields. For samples of other types of formulas, see Examples of Validation Rules and Useful Default Field Value Formulas.
This document contains the following categories of custom formula samples:
This formula evaluates Annual Revenue, Billing Country, and Type, and assigns a value of “Hot,” “Warm,” or “Cold.”
In addition, you can reference this Account Rating formula field from the contact object using cross-object formulas.
This formula returns a text value of “North,” “South,” “East,” “West,” or “Central” based on the Billing State/Province of the account.
This formula calculates the number of days since a contract with an account was activated. If the contract Status is not “Activated,” this field is blank.
This formula calculates how many days a contract is in the approval process. This example is a number formula field on contracts that uses a custom date field called Date in approval.
For details about using this function, see TODAY.
This formula field displays the month of the last account activity or “None” if there are no activities for the account.
This formula returns the month that your service-level agreement expires. This example uses a custom date field called SLA Expiration Date.
For details about using this function, see MONTH.
For details about using the function used in these formulas, see HYPERLINK.
This formula creates a linkable phone number field that automatically dials the phone number when clicked. In this example, replace "servername" and "call" with the name of your dialing tool and the command it uses to dial. The merge field, Id, inserts the identifier for the contact, lead, or account record. The first Phone merge field tells the dialing tool what number to call and the last Phone merge field uses the value of the Phone field as the linkable text the user clicks to dial.
Use this example of a custom formula field called Days Open to display different text depending on the number of days a case has been open:
The following text is displayed:
§ “Reassign” for any case open three days.
§ “Assign Task” for any case open two days.
§ “Maintain” for all other cases.
This formula calculates the number of days a case has been open. If the case is closed, it sets the result to null. Add this formula to a related list as the sort column to quickly see which open cases have been open the longest. The formula returns zero if the case has been open for less than 24 hours.
This formula calculates the number of days a closed case was open or the number of days an open case has been open since the date the case was created. The formula returns zero if the case has been open for less than 24 hours.
This formula displays a text value of “RED,” “YELLOW,” or “GREEN,” depending on the value of a case age custom text field.
This formula calculates the percentage of specific custom fields that contain data. The formula checks the values of two custom number fields: Problem Num and Severity Num. If the fields are empty, the formula returns the value “0.” The formula returns a value of “1” for each field that contains a value and multiplies this total by fifty to give you the percentage of fields that contain data.
This formula sets the due date of a case based on the priority. If it is high, the due date is two days after it opens. If it is medium, the due date is five days after opening. Otherwise, the due date is seven days.
This formula prompts an agent with cross-sell offers based on past purchases.
This formula suggests a product based on the support history for a computer reseller. When the Problem custom field matches a field, the formula field returns a suggestion.
The following is a simple formula where commission is based on a flat 2% of the opportunity Amount.
This example calculates the commission amount for any opportunity that has a “Closed Won” stage. The value of this field will be the amount times 0.02 for any closed/won opportunity. Open or lost opportunities will have a zero commission value.
This formula calculates a commission rate based on deal size, returning a 9% commission rate for deals over 100,000 and an 8% commission rate for smaller deals.
This formula assigns the “YES” value to opportunities with a commission greater than or equal to one million. Note, this is a text formula field on opportunities that uses a custom currency field called Commission.
This formula determines what commission to log for an asset based on which is greater: the user's commission percentage of the price, the price times the discount percent stored for the account or 100 dollars. This example assumes you have two custom percent fields on users and assets.
For details about using this function, see MAX.
This date formula displays the account's Created Date field on the contacts page.
This percent formula displays the account's Discount Percent field on the contacts page.
This formula displays the standard Account Name field on the contacts page.
This formula displays the standard Account Phone field on the contacts page.
Use this formula to display the Account Rating field on the contacts page.
This formula displays the standard Account Website field on the contacts page.
If the account website URL is long, use the HYPERLINK function to display a label such as “Click Here” instead of the URL. For example:
This formula also adds the necessary "http://" or "https://" before a URL if neither were included in the URL field.
Use this formula to calculate a person’s age based on a standard field called Birthdate. The person’s Birthdate is subtracted from today’s date, which returns the number of days since the person’s Birthdate. This number is divided by the number of days in a year and rounded down to the nearest integer.
This formula displays the value “Yes” if the contact’s birthday falls in the current calendar month.
Contact's LinkedIn™ Profile
You can configure a link that appears on your contacts' profile page that sends you to their LinkedIn profile. To do so:
1. Click SetupCustomizeContactsButtons and Links.
2. Click New under Custom Buttons and Links
3. Enter a Label for this link, like LinkedInLink.
4. Enter this formula in the content box:
5. Click Save.
Remember to add this link to the Contact page layout in order for it to show up.
This formula displays the first five characters of the contact’s last name and the last four characters of the contact’s social security number separated by a dash. Note that this example uses a text custom field called SSN on contacts.
This formula displays the contact’s preferred contact method in a contact related list—work phone, home phone, or mobile phone—based on a selected option in a Preferred Phone custom picklist.
This formula assesses the importance of a contact based on the account rating and the contact's title. If the account rating is Hot or the title starts with Executive, then the priority is high (P1). If the account rating is Warm or the title starts withVP then the priority is medium (P2), and if the account rating is Cold then the priority is low (P3).
This formula displays a clickable Yahoo! Messenger icon indicating if the person is logged on to the service. Users can click the icon to launch a Yahoo! Messenger conversation with the person. This example uses a custom text field calledYahoo Name on contacts where you can store the contact's Yahoo! Messenger ID.
This formula field displays a formatted mailing address for a contact in standard format, including spaces and line breaks where appropriate depending on the country for the account.
This formula determines the telephone country code of a contact based on the Mailing Country of the mailing address.
This formula removes the parentheses and dash characters from North American phone numbers. This is necessary for some auto-dialer software.
This formula displays “Large Deal” for deals over one million dollars or “Small Deal” for deals under one million dollars.
This formula displays “Small” if the price and quantity are less than one. This field is blank if the asset has a price or quantity greater than one.
This formula checks the content of a custom text field named Product_Type and returns “Parts” for any product with the word “part” in it. Otherwise, it returns “Service.” Note that the values are case sensitive, so if a Product_Type field contains the text “Part” or “PART,” this formula returns “Services.”
This formula returns the date of a person's birthday in the current year, even if the person's birthday is on February 29th in a leap year.
This formula calculates today’s day of the week as a number (0 = Sunday, 1 = Monday, 2 = Tuesday, and so on).
Similarly, this formula substitutes the TODAY() function shown in the previous example with a custom date field called Sign Up Date. It returns the day of the week as a number for that field.
This formula calculates today’s day of the week and displays it as text. To determine the day of the week for a date field, use the formula below and replace “TODAY()” with that date field.
This formula displays the number of days between a specific date and the end of the month in which the date occurs.
Maintenance and Services Discount
This formula field uses two custom currency fields: Maintenance Amount and Services Amount. It displays “Discounted” on an opportunity if its maintenance amount and services amount do not equal the opportunity Amount standard field value. Otherwise, it displays "Full Price."
Opportunity Discount Amount
This formula calculates the difference of the opportunity Amount less the Discount Amount. Note that Discount Amount is a custom currency field on opportunities.
Use this formula to calculate the discounted amount of an opportunity rounded off to two digits. This example is a number formula field on opportunities that uses a custom percent field called Discount Percent.
For details about using this function, see ROUND.
This formula adds a “Discount Approved” checkbox to an opportunity. It uses conditional logic to check the value of the approval flag before calculating the commission.
This example determines an employee's bonus amount based on the smallest of two amounts: the employee's gross times bonus percent or an equally divided amount of the company's performance amount among all employees. It assumes you have custom number field for Number of Employees, a custom percent field for Bonus Percent, and currency custom fields for the employee's Gross and company's Performance.
For details about using this function, see MIN.
This example formula determines which amount to provide in employee 401K matching based on a matching program of half of the employee's contribution or $250, whichever is less. It assumes you have custom currency field forContribution.
For details about using this function, see MIN.
This formula uses a custom tab to enable time tracking of hours worked per day. It uses a formula field to sum the hours per week.
This formula determines total pay by calculating regular hours multiplied by a regular pay rate, plus overtime hours multiplied by an overtime pay rate.
This formula displays the text “Expense-” followed by trip name and the expense number. This is a text formula field that uses an expense number custom field.
This formula calculates the interest that will have accumulated after T years, if continuously compounded.
For details about using this function, see EXP.
This formula calculates the number of consulting days times 1200 given that this formula field is a currency data type and consulting charges a rate of $1200 per day. Note that Consulting Days is a custom field on opportunities.
This formula provides a simple calculation of gross margin. In this formula example, Total Sales and Cost of Goods Sold are custom currency fields.
This formula returns the date five days after the contract start date whenever Payment Due Date is blank. Payment Due Date is a custom date field on contracts.
For details about using this function, see BLANKVALUE.
This formula determines if the payment due date is past and the payment status is “UNPAID.” If so, it returns the text “PAYMENT OVERDUE” and if not, it leaves the field blank. This example uses a custom date field called Payment Due Dateand a text custom field called Payment Status on contracts.
Yahoo! Instant Messenger™ Image
This formula displays an image that indicates whether a contact or user is currently logged in to Yahoo! Instant Messenger. Clicking the image launches the Yahoo! Instant Messenger window. This formula uses a custom text field called Yahoo Name to store the contact or user’s Yahoo! ID.
“Skype Me™” Auto Dialer Button
This formula displays an image that looks like a push button. Clicking the button automatically dials the specified phone number.
Flags for Case Priority
This formula displays a green, yellow, or red flag image to indicate case priority.
For details about using this function, see IMAGE.
This formula displays a 30 x 30 pixel image of a red, yellow, or green, depending on the value of a Case Age custom text field.
Traffic Lights for Status
This formula displays a green, yellow, or red traffic light images to indicate status, using a custom picklist field called Project Status. Use this formula in list views and reports to create a “Status Summary” dashboard view.
Stars for Ratings
This formula displays a set of one to five stars to indicate a rating or score.
Consumer Reports™-Style Colored Circles for Ratings
This formula displays a colored circle to indicate a rating on a scale of one to five, where solid red is one, half red is two, black outline is three, half black is four, and solid black is five.
Horizontal Bars to Indicate Scoring
This formula displays a horizontal color bar (green on a white background) of a length that is proportional to a numeric score. In this example, the maximum length of the bar is 200 pixels.
For details about using this function, see IMAGE.
This formula creates a link to an application outside Salesforce, passing the parameters so that it can connect to Salesforce via the Web services API and create the necessary event.
This formula creates a link to FedEx, UPS, or DHL shipment tracking websites, depending on the value of a Shipping Method custom picklist field. Note that the parameters shown in this example for FedEx, UPS, and DHL websites are illustrative and do not represent the correct parameters for all situations.
This formula creates a linkable phone number field that automatically dials the phone number via the Skype VOIP phone application. It requires installation of the Skype application (a third-party product not provided by salesforce.com) on your desktop.
This formula checks to see if a lead is open and if so, calculates the number of days it has been open by subtracting the date and time created from the current date and time. The result is the number of days open rounded to zero decimal places. If the lead is not open, this field is blank.
This formula calculates the percent of certain lead fields that your sales personnel enter. The formula field checks the values of two custom number fields: Phone and Email. If the fields are empty, the formula returns the value “0.” The formula returns a value of “1” for each field that contains a value and multiplies this total by fifty to give you the percentage of fields that contain data.
This formula returns a number value for the text value in the auto-number field Lead Number. This can be useful if you want to use the Lead Number field in a calculation, such as round-robin or other routing purposes. Note that auto-number fields are text fields and must be converted to a number for numeric calculations.
For details about using this function, see VALUE.
The following formula example for leads assumes you have three lead queues and you want to assign an equal number of incoming leads to each queue. You can also assign cases using a similar formula.
This formula is for a custom formula field named Round_Robin_ID that assigns each lead a value of 0, 1, or 2. This formula uses a custom auto-number field called Lead Number that assigns each lead a unique number starting with 1. The MOD function divides the lead number by the number of lead queues available (three in this example) and returns a remainder of 0, 1, or 2. Use the value of this formula field in your lead assignment rules to assign lead records to different queues. For example:
§ Round_Robin_ID = 0 is assigned to Queue A
§ Round_Robin_ID = 1 is assigned to Queue B
§ Round_Robin_ID = 2 is assigned to Queue C
For details about using this function, see TODAY.
This formula returns the month in text for the close date of an opportunity. Use this example when building a custom report that groups opportunities by the month of the Close Date.
This formula calculates total revenue from multiple products, each with a different probability of closing.
This formula calculates maintenance fees as 20% of license fees per year. Maintenance Years is a custom field on opportunities.
This formula calculates an opportunity amount based on a monthly subscription rate multiplied by the subscription period.
Opportunity Additional Costs
This formula calculates the sum of the opportunity Amount, maintenance amount, and services fees. Note that Maint amount and Service Fees are custom currency fields on opportunities.
This formula uses conditional logic to populate an Opportunity category text field, based on the value of the Amount standard field. Opportunities with amounts less than $1500 are “Category 1,” those between $1500 and $10000 are “Category 2,” and the rest are “Category 3.” This example uses nested IF statements.
This formula takes a group of opportunity fields and calculates what percent of them are being used by your sales personnel. This formula field checks five fields to see if they are blank. If so, a zero is counted for that field. A “1” is counted for any field that contains a value and this total is divided by five (the number of fields evaluated). Note that this formula requires you select the Treat blank fields as blanks option under Blank Field Handling while the Advanced Formula subtab is showing.
For details about using this function, see ISBLANK.
This formula creates reminder date based on seven days before the close date of an opportunity. Use this formula field in a workflow rule to create an event for the appropriate user to take action.
This formula returns the expected revenue amount of an opportunity in text format without a dollar sign. For example, if the Expected Revenue of a campaign is “$200,000,” this formula field displays “200000.”
For details about using this function, see TEXT.
This formula splits opportunity amount between multiple sales representatives. The total reps custom field indicates the total number of representatives on the deal.
This formula estimates professional service fees at an average loaded rate of $1200 per day. Consulting Days is a custom field on opportunities.
This formula Identifies a relevant document in the Documents tab based on opportunity Stage. Use document IDs in the form of “00l30000000j7AO.”
This formula creates a hyperlink that opens a stage-specific document stored in the Documents tab. It uses the previously defined custom formula field that identifies a document based on opportunity Stage. See Stage-Based Sales Document Selection.
This formula calculates the 2% commission amount of an opportunity that has a probability of 100%. All other opportunities will have a commission value of zero.
This formula calculates both recurring and non-recurring revenue streams over the lifetime of a contract.
This formula calculates intermediate milestone dates by subtracting days from the end date (for projects that are planned based on end date).
This formula uses a simple scoring algorithm to rank customers a high score for positive survey results in Salesforce.