Creating a Top N Stacked Bar Chart View

Published: 12 Jun 2014
Last Modified Date: 03 Jan 2019


How to create a stacked bar view that will show the Top N results.


Tableau Desktop


This example uses the Superstore sample data set.

Step 1: Create the basic view 

  1. Place SUM(Sales) on Columns.
  2. Place Product Name on Rows.
  3. Place Region on Color.

Step 2: Create Calculated Fields

  1. Select Analysis > Create Calculated Field.
  2. Name the field. In this example, the field is named Total Sales Per Item.
  3. Type the following into the Formula field, then click OK: WINDOW_SUM(SUM([Sales])).
  4. Select Analysis > Create Calculated Field.
  5. Name the field. In this example, the field is named Rank.
  6. Type the following into the Formula field, then click OK: RANK_DENSE([Total Sales Per Item]).

Step 3: Configure Calculated Fields 

  1. Drag Rank to Filters.
  2. Click OK.
  3. Right-click Rank in the Filters shelf.
  4. Select Edit Table Calculation.
  5. Configure Rank as follows:
    • Select Specific Dimension
    • Move Region above Product Name and check both boxes.
    • At the level: Product Name.
  6. Select Nested Calculations > Total Sales Per Item.
  7. Configure Total Sales Per Item as follows:
    • Compute using: Region.
  8. Click OK.

Step 4: Complete the view

  1. Ctrl+Click and drag Rank from Filters to Rows.
  2. Right-click Rank in the Rows shelf.
  3. Select Discrete.
  4. Right-click Product Name in the Rows shelf.
  5. Select Sort and configure as follows, then click OK
    • Sort order: Descending 
    • Sort by: 
      • Field: Sales 
      • Aggregation: Sum 
  6. Right-click Rank on the Filters shelf and select Show Filter.
  7. Filter view as desired.

Additional Information

Note: If multiple dimensions are used on Rows, WINDOW_SUM may not produce the desired result. In this case, use the TOTAL() function instead.

Discuss this article... Feedback Forum
Did this article resolve the issue?