We use Salesforce CRM to manage our sales business. We wanted to calculate and store the difference between the Target Sales and Actual Sales in a custom field.
As a Salesforce Admin, I created a Formula Field on the opportunity object. In the formula, I used the ABS() function so that the result always shows the difference as a positive number, whether the salesperson achieved less than the target (negative value) or more than the target (positive value).
This way, the field clearly shows the Sales Gap in Salesforce without confusion of negative numbers.
In this article, we will learn about the ABS() function in Salesforce and how we can use it to calculate the absolute value of numerical data. Additionally, we will focus on its syntax and provide some practical examples.
What is the ABS() Function in Salesforce?
In Salesforce, we have multiple formulas and functions used to perform mathematical calculations, and the ABS() function is one of these 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 value of a 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 keep in mind that 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”. For this, we use the ABS() function to 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.
ABS() function in Salesforce: Calculate the Absolute Value in Salesforce
Now, let’s understand how to create and use the ABS() function in Salesforce to calculate the absolute value of numerical data.
- Go to the Gear Icon. -> Click on the Setup. -> Select the Object Manager tab. Select the Object on which you want to create the Formula Field. Here, I’m going to create an Opportunity Object.
- In the Opportunity setup, click on Fields and Relationships to create a new field, then click the New button.

- In this step, we will use a formula to calculate and display the date after adding days to the given date, and display it on the product object. To do this, select the Formula option from the data type and click Next.

- Next, provide the Field Label and API Name for the formula field. Then, since we want to display the next date after adding days to the given date, in the Formula Return Type, select Date and click on the Next button.

- In the formula editor, enter the formula below and click the Next button.
- 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.
- Click the “Check Syntax” button to validate the formula and ensure that it contains no errors.
- Optionally, we can “Handle the empty field” as well as we can define the “Description” and “Help text” if we want.
- Click on the “Next” button to move ahead.

- Select the Field Level Security for the formula field, and then select the profiles to make the field visible to those profiles. The field will be visible for the profiles selected from the Visible column.
- After selecting the profiles, click on the Next button.

- In this step, we must select the field’s visibility on the object’s page layouts. In this case, we have created a formula field for the reports, allowing us to choose not to display it on the page layouts.
- Uncheck the checkboxes of the page layouts to prevent the field from displaying on them. After this, click on the Save button.

- We can use the formula field once it has been created. 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.
Conclusion
With this, we have concluded that the Salesforce function ABS() is an excellent tool for working with numerical data. In addition, we have learned practical examples, such as calculating differences, net changes, and handling negative numbers.
Moreover, we have also understood the concept of the ABS() function with its syntax and procedure for calculating the absolute value in Salesforce.
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.