Pivot Table Formula in Excel (Table of Content)
- Pivot Table Formula in Excel
- Custom Field to Calculate Profit Amount
- Advanced Formula in Calculated Field
Pivot Table Formula in Excel
Pivot Table is a tool which allows us to analyze large data ranges. We can analyze, interpret, and do many other things without breaking much of our head and sweat. It can give almost everything which is there in the source data.
If some of the information is there in the source data we may need to calculate this for ourselves. For example, if we have a Total Sales Amount and Total Cost we may need to calculate the Total Profit or Loss on our own.
We need not do this in the source but we can do this inside the pivot table itself, these are called Calculated Fields inside the pivot table. We can use custom formulas to make the data to tell more story from the data. Calculated Fields allows us to build a new calculated column which does not exist in the actual data source.
In this article, we will demonstrate the ways of using Pivot Table Calculated Fields to build new columns based on our requirement.
Custom Field to Calculate Profit Amount
This is the most often used calculated field in the pivot table. Take a look at the below data, I have Country Name, Product Name, Units Sold, Unit Price, Gross Sales, COGS (Cost of Goods Sold), Date, and Year column.
Let me apply the pivot table to find the total sales and total cost for each country. Below is the pivot table for the above data.
The problem is I don’t have a profit column in the source data. I need to find out the profit and profit percentage for each country. We can add these two columns in the pivot table itself.
Step 1: Select a cell in the pivot table. Go to Analyze tab in the ribbon and select Fields, Items, & Sets. Under this select Calculated Field.
Step 2: In the below dialog box give a name to your new calculated field.
Step 3: In the Formula section apply the formula to find the Profit. The formula to find the Profit is Gross Sales – COGS.
Go inside the formula bar > Select Gross Sales from the below Field and double click it will appear in the Formula bar.
Now type minus symbol ( – ) and select COGS > Double click.
Step 4: Click on ADD and OK to complete the formula.
4.9 (3,113 ratings)
Step 5: Now we have our TOTAL PROFIT Column in the pivot table.
This calculated field is flexible, it is not only limited to Country-wise analysis but we can use this for all kind of analysis. If I want to see the analysis country-wise and product–wise I just have to drag and drop the product column to the ROW field it will show the breakup of profit for each product under each country.
Step 6: Now we need to calculate the profit percentage. The formula to calculate the Profit Percentage is Total Profit / Gross Sales.
Go to Analyze and again select Calculated Field under Fields, Items, & Sets.
Step 7: Now we must see the newly inserted calculated field Total Profit in the Fields list. Insert this field to the formula.
Step 8: Type divider symbol (/) and insert Gross Sales Field.
Step 9: Name this Calculated Field as Profit Percentage.
Step 10: Click on ADD and OK to complete the formula. We have Profit Percentage as the new column.
Advanced Formula in Calculated Field
Whatever I have shown now is the basic stuff of Calculated Field. In this example, I will show you the advanced formulas in pivot table calculated fields. Now I want to calculate the incentive amount based on the profit percentage.
If the Profit % is >15% incentive should be 6% of the total profit.
If the Profit % is >10% incentive should be 5% of the total profit.
If the Profit % is <10% incentive should be 3% of the total profit.
Step 1: Go to Calculated Field and open the below dialog box. Give the name as Incentive Amount.
Step 2: Now I will use IF condition to calculate the incentive amount. Apply the below formulas as shown in the image.
=IF (‘ProfitPercentage’>15%, ‘TotalProft’*6%, IF(‘ProfitPercentage’>10%, ‘Total Proft’*5%, ‘Total Proft’ *3%))
Step 3: Click on ADD & OK to complete. Now we have an Incentive Amount column.
Limitation of Calculated Field
We have seen the wonder of Calculated Fields but it has some of the limitations as well. Now take look at the below image, if I want to see the breakup of Product-wise Incentive amount we will have wrong SUB TOTAL & GRAND TOTAL of INCENTIVE AMOUNT.
So be careful while showing the Subtotal of calculated fields. It will show you the wrong amounts.
Get List of All the Calculated Field Formulas
If you do not know how many formulas are there in the pivot table calculated field you can get the summary of all these in a separate worksheet.
Go to Analyze > Fields, Items, & Sets –> List Formulas.
It will give you a summary of all the formulas in a new worksheet.
Things to Remember About Pivot Table Formula in Excel
- We can delete, modify all the calculated fields.
- We cannot use formulas like VLOOKUP, SUMIF, and much other range involved formulas in calculated fields i.e. all the formulas which require range cannot be used.
This has been a guide to Pivot Table Formula in Excel. Here we discussed the Steps to Use Formula of Pivot Table in Excel along with Examples and downloadable excel template. You may also look at these useful functions in excel –