I recently joined a USA-based IT company that uses the powerful customer relationship management system “Salesforce” to deal with the business world. One day, I was assigned the task of calculating the maximum lead score across all leads.
As a solution, I discovered that Salesforce gives us the function named “Max() Function”, which is used to calculate the maximum value of the field.
In this tutorial, we will learn the MAX() Function in Salesforce and how to calculate the maximum value of a field. In addition, we will learn the syntax and some practical business use cases of the MAX() Function.
So, let’s move and learn how to use this MAX() function to calculate the maximum value of the field in Salesforce.
What is the MAX() Function in Salesforce?
The MAX() Function is one of numerous mathematical aggregate functions in Salesforce that can be used to perform mathematical computations.
The MAX() function returns the maximum value (the highest number) from a list of numbers in Salesforce.
The syntax of the MAX() Function is as given below:
MAX(number/field/formula)The parameter value may be a number, a field, or an advanced formula used as the argument to the MAX() function.
Furthermore, the MAX() function only supports numeric data types, such as Numbers, Decimals, and Currency. And if we try to use text, dates, or other non-numeric data types, it will produce an error.
Now, let’s take an example to help us understand the concept and syntax of the MAX() function.
Suppose we want to find out the maximum number of users associated with an account. For this, I use the MAX() function in Salesforce, and here is the formula for this:
MAX(NumberOfUsers__c)With this, we learned the syntax, explanation, and example of the MAX() function. Let’s go on and see how to use Salesforce Lightning to determine the highest number from a list of numbers.
MAX() Function in Salesforce: Calculate the Maximum Value of the Field
Here are the steps to find out the maximum value of the field in Salesforce Lightning:
- Log in to Salesforce org, then click the “Gear Icon” in the top right corner of the page. Click “Setup” from the dropdown menu to continue.

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

- Search for the object in the search bar where we wish to utilise the MAX() function. In this case, I search for the “Contact” object to track the client’s maximum age based on their date of birth.
- Now, click the “Contact” object; it will redirect us to the contact page.

- On the left side of the page, click the “Field & Relationship“ option. Click on the “New” button to create a new field where we can use the MAX() function.

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

- 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 “Maximum Age”.
- Choose the “Data Type“ for the field for which we want to calculate the maximum age of the client.
- Here, I select the data type as “Number” to get the formula return type as a number, so I check the radio button in front of it, and I also set the “Decimal Place” to 0.
- Move to the next step by clicking on the “Next” button.

- Move to the advanced formula editor, and enter the formula that uses the MAX() function. In this case, I want to calculate the maximum age of the client using the MAX() function. Here is the formula:
MAX(YEAR(TODAY()) - YEAR(Birthdate))- Here, we subtract the birth date year YEAR(Birthdate) from the current year YEAR(TODAY()).
- Then we pass the result to the MAX() function to calculate the client’s maximum age.
- Click on the “Check Syntax” button to validate the formula and ensure that there are no errors.
- Optionally, we can “Handle the empty field,” and we can also define the “Description” and “Help text” if we want.
- In this case, I set the Description to “Find Maximum Age of the Contact” and the Help Text to “Use MAX Function”.
- Click on the “Next” button to move to the formula field-level security step.

- Select the relevant “Field Level Security“. I have selected “Visible” in this case because I want it to be visible to everyone. Then, click on the “Next” button.

- Now, select the appropriate “Page Layout“ where we want to be visible.
- Click on the “Save” button to save the formula field.

We can use the formula field once it’s created. Let’s look at an example:
- Open the Contact Tab and create a new contact with the “Birth Date” field.
- After that, click on the Details section, and here the “Maximum Age” field appears, which shows you the result of the MAX() function.

As a result, we now know how to calculate the maximum value of a field in Salesforce.
Conclusion
With this, we have concluded that the MAX() Function in Salesforce is a great and efficient way to find out the maximum value from the list. In addition, we focused on the syntax and various real-world business-related examples of the MAX() Function.
Furthermore, we covered the process of calculating maximum value using the MAX() Function in Salesforce Lightning and in Salesforce Classic step by step.
You may like to read:
- LN Function in Salesforce | Calculate natural logarithmic value in Salesforce
- MIN() Function in Salesforce | Calculate minimum value in Salesforce
- Calculate cosine value in Salesforce
- ATAN() Function in Salesforce
- Salesforce DAY Function
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.