Calculating percentages

One of the most common type of measures is the percentage of a value within a population. Tableau provides options for converting values in a row or column to fractions of row or column totals; however, we can also create new fields with some calculated values presented as percentages.

Getting ready

Let's use the sample file Sample – Superstore Sales (Excel). Open a new worksheet and select Sample – Superstore Sales (Excel) as the data source.

How to do it...

Once the data is loaded on the worksheet, perform the following steps to create a new calculated field:

  1. To calculate the profit to sales ratio, right-click on the Measures pane and select Create Calculated Field.
  2. In the Name box, enter My Profit Ratio.
  3. In the Formula box, enter sum([Profit])/sum([Sales]) as shown in the following screenshot:
    How to do it...
  4. Right-click on My Profit Ratio from the Measures pane, expand Default Properties, and select Number Format as shown in the following screenshot:
    How to do it...
  5. In the Number Format options box, select Percentage and hit OK.

How it works...

In the calculated field, we aggregated the Profit and Sales fields before dividing them. By calculating this way, we summed the Profit and Sales fields individually and then performed the division. This is different from dividing profit and sales first and then summing those values—this type of operation is a row-level operation and is suitable for many occasions. However, we have to remember to aggregate fields to avoid unexpected results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset