In this Salesforce tutorial, we will learn about the ABS() function and how we can use it to calculate the absolute value of numerical data. In addition, we will also focus on its syntax and some practical examples.
While working in a Sales Organization that uses Salesforce as a customer relationship management tool to track their sales. I got a task to calculate the difference between target sales and actual sales.
Here I found an ABS() function in Salesforce that helped me to calculate the absolute difference. Now, let us discuss in detail, how to use the Salesforce ABS() function to calculate the absolute value of a number in Salesforce Lightning as well as Salesforce Classic.
What is ABS() function in Salesforce
In Salesforce, we have multiple functions that are used to perform mathematical calculations and the ABS() function is one of the mathematical functions.
This ABS() function is used to calculate the absolute value of a number. The absolute value represents the magnitude of a number without considering its sign.
In layman’s terms, the ABS() function is used to calculate the absolute number which gives the positive value of a number as a result without considering whether the original number was positive or negative.
Moreover, we should be kept one thing in mind the ABS() function works only on numeric data types such as Decimal, Integer, or Double. If you use it with other data types such as text, date, or other non-numeric data types it will produce an error.
Syntax and Usage of ABS() function in Salesforce
The syntax of the ABS() function is given below:
ABS(number/field/formula)
The number/field/formula parameter is the value for which we wish to determine the absolute value. The value specified in the parameter can be a field, a numeric constant, or a formula.
Let’s see an example to clearly understand the concept and syntax of the ABS() function.
Suppose, we want to calculate the absolute value of the numeric field value called “Net Profit” and for this, we use the ABS() function and calculate it. The formula is as follows:
ABS(Net Profit)
With this, we have understood the ABS() function with its syntax, important points, and example. Now, we will move and try to understand the steps to calculate the absolute value in Salesforce Lightning.
How to calculate the absolute value in Salesforce Lightning
Here, are the steps to calculate the absolute value in Salesforce Lightning:
1: First, log in to Salesforce Lightning mode and navigate to the right corner of the page, then click on the “Gear Icon” (⚙). Now, from the dropdown menu (⬇) click on the “Setup”.

2: From the left side of the menu, click on “Object Manager”.

3: Search for the object in the search bar where we wish to utilize the ABS() function. In this case, I search for the “Opportunity” object as I want to track the sales.
4: Now, click on the “Opportunity” object and it will redirect us to the Opportunity Page.

5: From the left side of the page click on the “Field & Relationship” option.
6: Click on the “New” button to create a new field where we can use the “ABS() function”.

7: It will redirect to the “Choose the field type” page, now check the radio button in front of the “Formula” data type.
8: To proceed to the next step, click on the “Next” button.

9: Enter the “Field Label” for the formula and the unique “Field Name” will be automatically populated. In this case, I entered the field label named “Absolute Sales Variance”.
10: Choose the “Data Type” for the field for which we want to calculate the absolute value. Make sure the data type must be of a numeric type such as “Number“, “Currency“, etc.
In this case, I check the radio button in front of the “Currency” to set it as the formula return type.
11: Now, to move to the next step click on the “Next” button.

12: Move to the advance formula editor, and enter the formula that uses the ABS() function to calculate the absolute value.
In this case, I want to calculate the absolute value of the sales variance i.e. the difference between target sales and actual sales using the ABS() function. Here, is the formula:
ABS(Target_Sales__c - Actual_Sales__c)
- In this formula, we subtract the “Actual_Sales__c” field from the “Target_Sales__c” field.
- Then we use the ABS() function with it to calculate the absolute value of the difference between actual sales and target sales.
13: Click on the “Check Syntax” button to validate the formula and ensure that there are no errors.
14: Optionally, we can “Handle the empty field” as well as we can define the “Description” and “Help text” if we want.
15: Click on the “Next” button to move ahead.

16: Choose the appropriate field “Level Security”. Here, I check the “Visible” checkbox as I want it to be visible to all. Then, click on the “Next” button.

17: Now, select the appropriate “Page Layout” where we want to be visible.
18: Lastly, click on the “Save” button to save the formula field.

We can use the formula field once we’ve created it. Let’s look at an example:
- Open the Opportunity Tab and create a New Opportunity with the fields Target Sales and Actual Sales.
- After that, click on the Details section, and here the Absolute Sales Variance field appears which shows you the result of the ABS() function.

As a result, we now know how to calculate the absolute value in Salesforce Lightning. Now, we’ll look at how to calculate the absolute value in Salesforce Classic.
Read ACOS() Function in Salesforce | Calculate inverse cosine value in Salesforce
How to calculate the absolute value in Salesforce Classic
Here, are the steps to calculate the absolute value in Salesforce Classic:
1: From the Salesforce Lightning to open your Salesforce Classic edition. Click on Avtar and then click Switch to Salesforce Classic.

2: After that, click on the Setup option.

3: Now, scroll down to the Build section. Then under Customize, select the object for whom field we want to use the ABS() function. In this case, I select the “Cases” object as I want to track the response time.
4: Click on the “Cases” dropdown and select the “Fields” option to get the option of the new field.

5: Now scroll down to the “Custom Fields & Relationships” and click on the “New” button to create a new formula field.

6: It will redirect to the “Choose the field type” page, now check the radio button in front of the “Formula” data type.
7: To proceed to the next step, click on the “Next” button.

8: The unique “Field Name” will be filled out automatically when you enter the “Field Label” for the formula. I entered “Response Time Variance” into the field labeled in this instance.
9: Select the “Data Type” for field that we want to calculate the absolute value. Make sure the data type must be of a numeric type such as “Number“, “Currency“, etc.
In this case, I check the radio button in front of the “Number” to set it as the formula return type. I also set the decimal place to 0.
10: Now click the “Next” button to go to the next step.

11: Move to the advance formula editor, and enter the formula that uses the ABS() function to calculate the absolute value.
In this case, I want to calculate the absolute value of the response time variance i.e. the difference between target response time and initial response time using the ABS() function. Here, is the formula:
ABS(Target_Response_Time__c - Initial_Response_Time__c)
- In this formula, we subtract the “Target_Response_Time__c” field from the “Initial_Response_Time__c” field.
- Then we use the ABS() function with it to calculate the absolute value of the difference between the target response time and the initial response time.
12: To check the formula and make sure there are no mistakes, click the “Check Syntax” option.
13: Optionally, we can define the “Description” and “Help text” as well as “Handle the empty field” if we prefer.
14: Click on the “Next” button to move ahead.

15: Select the relevant “Level Security” field. I have selected “Visible” in this case because I want it to be visible to everyone. Following that, select “Next” to move ahead.

16: Now, select the appropriate “Page Layout” where we want this field to be visible.
17: Lastly, click on the “Save” button to save the formula field.

We can use the formula field once we’ve created it. Let’s look at an example:
- Open the Case Tab and create a New Case with the fields Target Response Time and Initial Response Time.
- On Save, it will redirect us to the Detail page, and here the Response Time Variance field appears which shows us the result of the ABS() function.

As a result, we now know how to calculate the absolute value in Salesforce Classic.
Conclusion
With this, we have concluded that the Salesforce function ABS() is a great tool for working with numerical data. In addition, we have learned practical examples such as calculating differences, net changes, handling negative numbers, etc.
Moreover, we have also understood the concept of the ABS() function with its syntax and procedure of calculating the absolute value in Salesforce Lightning and Salesforce Classic.
You may like to read the following articles:
- Salesforce Formula Field to Calculate Age
- Salesforce Date Formula Business Days
- ATAN() Function in Salesforce | Calculate inverse tangent value in Salesforce
- ASIN() Function in Salesforce | Calculate inverse sine value in Salesforce
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.