In this Salesforce tutorial, we will learn the LOG() and how we can use it for calculating the logarithm value of numerical data. Moreover, we will focus on the syntax of the LOG() function and some practical examples for implementation.
Recently I worked for a company that utilizes Salesforce as a CRM tool. While working here, I was given the responsibility to determine changes in the price of the product based on profit margins.
I discovered a LOG() function as a solution for this, which enabled me to determine product pricing. Let’s now go into more detail about how to use Salesforce Lightning and Salesforce Classic components for using the LOG() function to determine the logarithmic value.
What is LOG() function in Salesforce
The LOG() function is one of the many mathematical functions available in Salesforce that is used to perform mathematical calculations. This LOG() function is short for “Logarithmic” in Salesforce.
Basically, this LOG() function is used to calculate the logarithm value of a given value with a base value of 10. Furthermore, the LOG() function only supports numeric data types like Decimals and Integers. And if we try to use text, dates, or other non-numeric data types, it will produce an error.
Syntax and Usage of LOG() function in Salesforce
Below is the syntax for the LOG() function in Salesforce:
The value of the number/field/formula parameter is the value for which we are trying to determine the logarithmic value with the base value of 10 by default. The value of the parameter can be a field, a constant number, or a complex formula.
Let’s see an example to better understand the LOG() function in Salesforce:
As I have discussed above that I got a task to find “Product Pricing” and for this, I will use the LOG() function of Salesforce. Here, is the formula:
Old_Price__c * LOG(1 - Profit__c)
With this, we have learned LOG() function syntax, logic, and example. Now let’s move ahead and learn to find out the logarithmic value in Salesforce Lightning.
Calculate the logarithmic value of number in Salesforce Lightning
The steps to determine the logarithmic value of the number in Salesforce Lightning:
Step 1: Log in to Salesforce Lightning mode, then click on the “Gear Icon” located in the top right corner of the page. To proceed, select “Setup” from the dropdown menu.
Step 2: From the menu’s left side, click on “Object Manager”.
Step 3: Now, search for the object for which you want to use the LOG() function in the search bar. As I want to track the order fulfillment, in this example, I look up the “Order” object.
Step 4: Click on the “Order” object, and it will redirect to the order page.
Step 5: From the menu on the left-hand side of the page, click on “Field and Relationship”.
Step 6: To create a formula field where we will use the LOG() function, click on the “New” button.
Step 7: Now, it redirects to the “Choose the field type” page. Here, select the “Formula” as the data type by checking the radio button next to it.
Step 8: To proceed, click on the “Next” button.
Step 9: After entering the “Field Label” for the formula, the “Field Name” will be filled in automatically. In this instance, I entered “Order Fulfilment” as the field label.
Step 10: Select the “Data Type” for the field on which we want to apply the LOG() function. As we know LOG() function only accepts the numeric data type.
In this case, I choose the “Number” as the formula return type and also set its “Decimal Value” to 2 as I only want it to return the result with 2 decimal positions.
Step 11: Click on the “Next” button to proceed to the next step.
Step 12: To compute Order Fulfilment by using the LOG() formula, enter the formula in the advanced formula editor. The formula is as follows:
5 * LOG(Volume__c)
Here, we find the logarithmic value of the field named “Volume__c” using the LOG() function and then multiply the resultant log value with the constant value 5 to find out the “Order Fuilment” field.
Step 13: To make sure that there is no mistake in the formula, click on the “Check Syntax” button.
Step 14: Optionally, we may define the “Description”, “Help Text”, and as well as “Handle the empty field” if you like.
Step 15: To continue, click on the “Next” button.
Step 16: Select the appropriate “Level Security” option. In this case, I have selected the “Visible” checkbox as I want it to be visible to everyone. Then, click on the “Next” button from the menu.
Step 17: Now, choose the “Page Layout” that will display your content.
Step 18: To save the advanced formula field, click on the “Save” button.
As a result, we now know how to calculate the logarithmic value of numbers in Salesforce Lightning. Now, we will look at how to calculate the logarithmic value of numbers in Salesforce Classic.
Calculate the logarithmic value of number in Salesforce Classic
The steps to calculate the logarithmic value of the number in Salesforce Classic:
Step 1: Open your Salesforce Classic edition from the Salesforce Lightning. Click on “Avtar” and then click on “Switch to Salesforce Classic”.
Step 2: Next, select “Setup” from the menu.
Step 3: Scroll down and move to the “Build” section and select “Customize” and search for the object on which field you want to use the LOG() function.
Here, I choose the “Price Books” object as I want to find out the revenue generated based on discounts.
Step 4: To get the option for creating a new formula field, click on the dropdown adjacent to the “Price Books” and choose the “Fields” option.
Step 5: Now scroll down and move to the “Custom Fields & Relationship” section and click on the “New” button to create a formula field.
Step 6: It moves to the “Choose the field type” page, select the “Formula” as the data type by checking up the radio button adjacent to it.
Step 7: Click on the “Next” button to move to the next proceeding step.
Step 8: Enter the “Field Label” for the formula and the unique “Field Name” will be filled out automatically. In this example, I specify the “Revenue Generated” as the field label.
Step 9: Next, choose the “Data Type” for the field where we are going to calculate the revenue generated from book prices using the logarithmic function. Make sure that you only choose the numeric data types otherwise, it will give an error.
In this case, I select the “Currency” as the formula return data type by clicking on the radio button in front of it. Moreover, I adjusted the “Decimal Place” to 0.
Step 10: Now, click on the “Next” button to proceed to the step enter formula.
Step 11: Go to the advanced formula editor and type the formula to compute the logarithmic value using the LOG() function.
In this instance, I want to use the LOG() function to determine the logarithmic value of the revenue generated. The formula is as follows:
Original_Price__c * LOG(1 - Discount__c)
- Here, we first subtract the “Discount__c” field from 1 and pass the resulting value to the LOG() function to find out the logarithmic value.
- After that, we multiply the resultant log value with the field named “Original_Price__c” to find out the field “Revenue Generated”.
Step 12: Select “Check Syntax” to review the formula and ensure there are no errors.
Step 13: If we’d like, we may specify the “Description” and “Help text” as well as “Handle the empty field”.
Step 14: To proceed, use the “Next” button.
Step 15: Choose the appropriate “Level Security” field. Because I want it to be visible to everyone, I have chosen “Visible” in this instance. Select “Next” to continue after that.
Step 16: Next, choose the suitable “Page Layout” for the area where we wish to display this field.
Step 17: In order to save the formula field, click the “Save” button.
Once we’ve established the formula field, we may use it. Let’s examine an illustration:
- Create a new price book with the field “Discount” and “Original Price” by opening the Price Book tab.
- When we click Save, we are taken to the Detail page, where the “Revenue Generated” field displays the LOG() function output.
With this, we have learned how to calculate the logarithmic value of numbers in Salesforce Classic.
With this, we have concluded that the Salesforce function LOG is a tool that is used for working with a numerical data value. In addition, we have learned practical examples such as calculating “Revenue Generated”, “Product Pricing”, “Order Fulfillment”, etc.
Furthermore, we have learned the concept of the LOG() function with its syntax and steps for calculating the logarithmic value in Salesforce Lightning and Salesforce Classic.
You may like to read:
- FLOOR() Function in Salesforce | Calculate round off nearest integer in Salesforce
- EXP() Function in Salesforce | Calculate exponential 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.