We will cover all that you need to know in order to calculate the total of an opportunity after a discount.
You will need the following fields:
- Opportunity Amount, Field Type: Currency
- Discount %, Field Type: Percentage
You can use the names that best suit your organization for these fields. You will just need to replace their names in the code snippet below.
If you want to learn how to create Fields, please visit the following tutorial:
Once you have the Opportunity amount and the Discount %, you are ready to create your Calculated field. To get started, click your portrait picture and then click 'Settings' (1). Then click 'Fields' under the Composer section, click on Fields (2) to display the available Apps and select the one for which you want to create Calculated fields. In this case, you will need to select your Deals / Opportunities app.
Once you have selected the App, click on the 'Add Field' button at the top right corner.
In this window, you will need to give your field a name and enter a description, which is optional. Then select 'Calculated' as the field type. Since we are calculating the total, we will choose currency for the Resulting value. Then copy & paste the code below:
var percentage =deal.Amount *deal.Discount;
var total =deal.Amount - percentage;
If your fields have different names, you would need to replace the bold parts with the right field name. Your field should look similar to the image below. Once you are done, click the Save button.
This calculation will happen when the information on the Amount and Discount fields have information. If one of the two fields is missing, then the Discount total won't be calculated.