50+ Salesforce Formula Examples

By Andreea Doroftei

When it comes to formulas, which are used in a variety of places in Salesforce, the first thing that comes to mind is probably the good old formula field! In case you haven’t yet created your first formula field, feel free to take a look at our interactive tutorial post – learning how to get started may be useful before exploring the examples below.

During this guide, we will dive into a variety of Salesforce formula examples, as well as the common scenarios in which formulas (used in different locations) can make your life as a Salesforce Admin much easier.

Formula Fields 101

Before going through the examples below, it’s worth nothing a few key considerations:

  • Formula fields are not editable. If the value displayed is not correct, the formula has to be changed so that the desired outcome will show up on records.
  • A formula field can be used for a range of calculations between fields and displaying data from related Object records, as well as displaying pictures.
  • After building a formula field, it is automatically populated for historical records as well.

You can check out all the current limitations and restrictions for formula fields here.

Salesforce Formula Examples

We’ve split the examples into several categories based on where they’re being used to cover a few more use cases. You can also categorize them in other ways depending on your preference.

Before starting to build your formulas, make sure you are familiar with at least the main operators and formula functions:

Field-Level Formulas

From the most simple to some of the most complex examples, formula fields are calculated after the record is saved, and can include a wide variety of functions, operators, and fields from the object at hand or related objects.

Calculate Basic Commission on Opportunities

IF(Amount < 10000, Amount * 0.10, Amount * 0.15)

A simple IF statement that checks if the Opportunity Amount is less than 10K – if so, the commission is 10%, and if it is greater, the commission is 15%. This calculates and displays that commission.

Calculate a Lead Score

(IF( AnnualRevenue = 0, 0, 10)) +
(IF(ISPICKVAL(Industry, “”) , 0, 10)) + 
(IF( MobilePhone = “”, 0, 10))

A basic Lead score formula that looks at whether fields are blank or not (and assigns them a score if not). We can then add these together. Please note, the ISPICKVAL function is necessary if you are using a picklist field.

Of course, even the Lead Source formula might become quite complex if you are looking forward to adding a few more attributes into the exist one. In such cases, keep in mind that you can go ahead and include comments within your formula similar to how Developers do in Apex, for other Admins to see in case they need more context.

(IF( AnnualRevenue = 0, 0, 10)) +
(IF(ISPICKVAL(Industry, "") , 0, 10)) +
(IF( MobilePhone = "", 0, 10)) +
(IF(Country = "United Kingdom",5,0)) /*temporarily added in order 
to increase the number of records from this country that will be sent to sales teams */

Calculate an Account’s Region

Here’s a great example of a formula field assigning West, Central, East, South, North, or Other based on the state. This was taken from the Salesforce Example page.

IF(ISBLANK(BillingState), “None”, 
“West”, IF(CONTAINS(“CO:ID:MT:KS:OK:TX:WY”, BillingState), 
“Central”, IF(CONTAINS(“CT:ME:MA:NH:NY:PA:RI:VT”, BillingState), “East”, 
BillingState), “South”, 
“North”, “Other”))))))

Using Images in Formula Fields

One of the best things about Formula Fields is the ability to display images as an output. So, in the example above with the Lead Score, instead of outputting a number, we could output an image to display how “Hot” the lead is.

Salesforce has a bunch of images that can be used straight out of the box. You can grab a whole list of them here (you will need to remove some of the URL, as instructed). There is also an AppExchange pack you can install to get hold of some more.

Continuing the example with Lead score, I’ll now show you a formula with images.

CASE( Lead_Score__c , 10 , 
IMAGE(“/img/samples/light_red.gif”, “light”), 
20,IMAGE(“/img/samples/light_yellow.gif”, “light”) ,
30 ,IMAGE(“/img/samples/light_green.gif”, 
“light”), “”)
READ MORE: Use Salesforce Image Formula Fields to Spice up Your Org

Using a CASE statement (similar to an IF statement but it can have more outcomes), we can look at our Lead Score field and assign an Image URL using the IMAGE function. If the score is 10, assign a red traffic light. If the score is 20, assign a yellow light. And if 30, assign the green. Easy!

Record Owner Category

This is a formula that, once again, can be used in validation rules, automations, and reports – you name it! It can be built as a formula field or directly within the automation, and it will be handy to know at all times whether the record owner for objects that support queue assignment is a queue or user.

IF(BEGINS(OwnerId, "005","User","Queue"))


IF(BEGINS(OwnerId, "00G","Queue","User"))

OR (if you prefer the formula output to be a checkbox)


Information from Parent Account

Fairly often, there might be a request to get and display certain information from records above in the Account hierarchy on individual records. The below IF() statement is perfect for a couple of levels higher, but CASE() can also be used, especially when multiple outcomes are possible.

IF(NOT(ISBLANK(Parent.Id)),Parent.AnnualRevenue, "")

Check if a Field Value Contains a Certain String

When possible, the ideal scenario is to use exact criteria, be it report filters or formulas, as equals is much more effective and less prone to errors than to check if a string contains a word. Sometimes, however, this does make sense.

For example, the Type field on the Opportunity in my developer sandbox has four values, of which three contain the word “existing”, based on which the Opportunity priority will be defined.

Note that Type is a picklist field, hence the function TEXT() will be used to transform the picklist into text within the formula.

IF(CONTAINS(TEXT(Type),"Existing"),"High", "Medium")

The CONTAINS() function, however, does not support multi-select picklists. In case that is what you’re looking forward to checking, you will have to use INCLUDES() instead, as well as the value the multi-select field should include. For this, I created a custom multi-select picklist for Type, just to be able to include more granular values which can be simultaneously selected.

IF(INCLUDES(Type__c,"Existing Customer"), "High","Medium")

Also, since we’re on the topic of multi-select picklists, there is a function that has been released more recently that you should know – this can be used in a formula, which returns the count of how many values are chosen in a multi-select picklist (although I’m hoping you don’t have too many of them!).



The transition to Lightning experience means that many of us would simply use a rich text component to display nicely organized hyperlinks at the top of the record page. However, there are still situations where the hyperlink formula is useful, as for once the lightning component can’t be displayed and accessed in reports or list views.

You could add a hyperlink formula field next to the Opportunity Next Step, to provide instructions on how to complete it directly on the detail page (in both Lightning and Classic). Also, you can add a couple links in as well – why not?

Tip: Make sure you use the shortest URL possible.

HYPERLINK("", "How to complete all relevant Next Steps") & BR() & 
HYPERLINK("", "How to Close Deals faster")

Number of Days Between Two Dates

Definitely the simplest date formula in Salesforce is to calculate the number of days between two dates. This can then be used in reports, perhaps as part of automation criteria, or to set deadlines for records to be actioned, and offer users additional visibility.

To find the number of days since a record was created, simply subtract the CreatedDate from TODAY().

TODAY() - DATEVALUE(CreatedDate)

Different date format

As you might already know, date formats in Salesforce have a tight relationship with user locale. There might be scenarios though where different date formats with different separators are needed simultaneously for other integrations or processes, and this is where the below formula will come to the rescue. For example, while the date fields generally follow the European DD/MM/YYYY format, a formula can easily help you obtain the dates in a YYYY-MM-DD format, and can be modified to adapt to any other format.

IF(MONTH(Your_Date__c) > 9,"","0")+TEXT(MONTH(Your_Date__c))+"-"+ 
IF(DAY(Your_Date__c) > 9,"","0")+TEXT(DAY(Your_Date__c))

For example, you could easily drop the IF() statements, and the format will become YYYY-M-D.


Find Out the Day of the Week

Perhaps the first formula that comes to my mind when thinking about date fields, is the one helping us find out the day of the week. For example, this way you can easily provide insight and analyze which days of the week are the most productive – to help close Opportunities, for example.

1, "Sunday", 
2, "Monday", 
3, "Tuesday", 
4, "Wednesday", 
5, "Thursday", 
6, "Friday", 
7, "Saturday",


Looking at Objects in particular? These articles should be your next stop:


We have plenty of resources available when it comes to Pardot (Marketing Cloud Account Engagement), including some interactive tutorials:

You may also be interested in the following articles:

Formulas Within Salesforce Reports

While most of us are already familiar with IF() row-level formulas in a Salesforce report, or a very simple average, it might slip our minds how much easier it is to create a report formula (rather than formula fields), when possible.

Row-Level Formula

A very easy one to use – row-level formulas allow you to define a value of the formula for each of the records in the report. For example, instead of creating a formula field to calculate the number of days between two date fields, you can do so in a report.

The below report only shows Accounts with one Closed Won Opportunity. I was curious to see how many days had passed between the Account being created and the Opportunity being closed. In my use case, whenever an Account is created, an Opportunity should be created as well.


Complex Report Formulas

In Salesforce reports, there are two formulas that, if understood and used correctly, can enable you to build powerful reports using the standard Salesforce reports only.

These formulas can be used at grouping levels, and as they are very specific to the calculation you’re looking forward to running in your report, make sure you read all documentation details, along with the examples.

The one use case of PARENTGROUPVAL() that I always go back to, is the possibility of showcasing the percentage each grouping level represents out of the total. This can prove to be really useful when looking forward to seeing a calculated procentual breakdown, for example, of how the Opportunities forecasted to close this FQ are doing.


Salesforce Reports Formula Fields

Check out the following articles for support with reports:

Validation Rules

Activity Validation

One question I have seen popping up a couple times recently relates to creation validation rules on Activities. It is possible, with the mention that the validation should be created on either the Task or Event object. The below example is on the Task object, and is meant to require more details if certain conditions are met:

ISPICKVAL(Status,"Waiting on someone else"),


ISPICKVAL(Priority,"High") &&
ISPICKVAL(Status,"Waiting on someone else") &&
LEN(Description) < 30

Following the same situation as above, instead of checking if the Comments field is blank, let’s make sure users always input a decent number of characters for the Comments of a High Priority Task. The LEN() function returns the count of the number of characters, helping you ensure the minimum level of detail is there.

AND(ISPICKVAL(Priority,"High"),ISPICKVAL(Status,"Waiting on someone else"), 
LEN(Description) < 30)

Checking the Previous Value of a Field

Especially in validation rules, PRIORVALUE comes to the rescue when users that normally have permissions to update certain fields, shouldn’t do that anymore. Common examples vary from editing key Opportunity fields when the Opportunity is closed, to updates on converted Leads. This one can also prevent admins from making unintentional mistakes on data points which should never undergo changes.

AND(IsClosed,PRIORVALUE(OwnerId) <> OwnerId)

More About Validation Rules

You can learn more about how to use validation rules in Salesforce with our step-by-step guide.

Salesforce Flow Formulas

Similar to Process Builder, being able to build formulas directly in the declarative automation tool is something that Salesforce has been doing quite well. The latest addition to the family is the ability to use formulas as an entry criteria for the flow, instead of individually selecting fields and defining filter logic – and, of course, covering more possible scenarios.

Make sure you take a look at the flow formulas considerations before embarking on this journey!

Entry Criteria Formula

There will be situations where you might need more than one of the same type of flow on the same object, and this is where the entry criteria comes into play. These will ensure that, in this case, your flow is not triggered by all changes to the record – the Salesforce recommendation is to always use entry criteria for a flow which should run when records are updated.

Of course, the advantage of using this formula is that not only can you filter by fields on the record, but also on related records. In this case, the flow I built will create a Task for the Opportunity Owner’s manager whenever the Stage is changed to a specific one, and the Annual Revenue of the Account exceeds a given threshold.

{!$Record.Account.AnnualRevenue} > 500000)

You can, however, always opt to use only fields from the triggering record, depending on your use case and business requirement, without having to select each field, operator, and value individually.

{!$Record.Amount} > 70000)

Flow Formula Resources

Perhaps the formula I use most often within flows (when creating records), is IF(). The reason behind this is that it’s far more efficient than having one Decision element, followed by two Create Records elements, depending on the outcome.

In this example, upon every new Opportunity creation, a specific placeholder Close Date is automatically updated depending on the Opportunity Type (which in my org is mandatory at record creation).

IF(ISPICKVAL({!$Record.Type},"New Customer"), 
TODAY() + 180, TODAY() + 90)

This formula can now be used to set the field value for Close Date, and it will be dynamic based on the value from the Type field.

Flow Formulas

When it comes to Flow formulas, we have you covered:

Other Formulas

Formulas in Approval Processes

There are endless possibilities with approval processes in Salesforce, which also provide a great way to document the history of approvals on records. Read our Ultimate Guide for more context.

Roll-Up Formulas

Check out the following resources:

Default Value Formula

It is especially useful to add a placeholder into a text field, perhaps with an example of a format – the formula editor helping to define the default value is something I find to be quite underused.


It is clear that formulas are here to stay. Whether you choose to calculate certain values in a report formula to save you from creating an extra field, or you save the business a few clicks by using a formula field to display data from a related record, day-to-day processes are sure to involve at least one of them.

What do you think of our Salesforce formula examples? And is there a formula that has saved the day for you? Feel free to share your experience in the comments section below.

The Author

Andreea Doroftei

Andreea is a Salesforce Technical Instructor at Salesforce Ben. She is an 18x certified Salesforce Professional with a passion for User Experience and Automation. 


    October 26, 2022 4:28 pm
    The one thing I wish that they could "fix" is that all formulas use the same AND and OR logic. I didn't see you use any within your blog post today, but some parts of Salesforce need && or || instead of the words AND or OR. Yes you could use the AND() and OR() but coming from a programming background this is not a normal thing I remember that is available within Salesforce.
    October 26, 2022 4:48 pm
    My 2 cents : Formula to display a "progress bar" : IMAGE('/resource/ProgressBar_full.png', '', 10, ( Nb_visits_done__c/Nb_visits_target__c * 100 )) & IMAGE('/resource/ProgressBar_empty.png', '', 10, (100 - Nb_visits_done__c/ Nb_visits_target__c * 100 )) Result is a progress bar displaying the percentage of accomplishment. You can add the following after : & ' ' & TEXT (ROUND(Nb_visits_done__c/ Nb_visits_target__c * 100, 0)) & '%' & ' (' & TEXT(Nb_visits_done__c) & ' / ' & TEXT(Nb_visits_target__c ) & ')' To get, after the bar, more explanations : percentage accomplished and the values (Nb accomplished / Objective)
    October 26, 2022 5:18 pm
    Hi, congratulations for your texts, very good. In the topic "Using Images in Formula Fields" comments on native images, but the link was missing. Which appexchange app has the images?
    Lucy Mazalon
    October 26, 2022 5:39 pm
    Thanks for flagging Rafael. This has been updated - have fun with image formulas!
    October 26, 2022 5:55 pm
    Very useful post! Thanks for this.
    October 27, 2022 9:16 am
    Great article. Did you know you can add comments to your formula . Prefix the comment with /* and postfix with */ . For example: IF(BEGINS(OwnerId, "005","User","Queue")) /* All User IDs start 005. Queue IDs start 00G */
    Andreea D
    October 27, 2022 12:20 pm
    Hello Andy! Thank you for pointing this out, as indeed this is something we're planning to include in the post to highlight the possibilities through examples using && and || too.
    Andreea D
    October 27, 2022 12:27 pm
    Hello Richard! Could be a personal preference, but I don't use comments within formulas unless they are very complex and actually need a more meaty explanation. Since you mentioned it maybe others aren't aware about the functionality being available, so I will add it within the post :) Thank you!
    March 06, 2023 10:21 pm
    Is there a way to figure out how many days between two dates, excluding weekends? I have tried numerous formula's and continue to get errors.
    Andreea D
    March 15, 2023 12:54 pm
    Hello Heidi! There an example of the formula you are looking for available on this help salesforce page : The number of weekdays between two dates is the sample one you should take a look at, hope it helps! Happy you asked the question, and I will make sure to add an example of my own to this post. Thank you!

Leave a Reply