KNOWLEDGE BASE

Pie charts are not sorted by descending order by Sum on a Map


Published: 27 Nov 2023
Last Modified Date: 28 Nov 2023

Issue

When visualizing pie charts on a map and sorting the dimension by the Color, it is not sorted as expected. In the following example, each pie chart is not sorted in descending order by sum of Sales, and the order is the same for each state.

User-added image

Environment

  • Tableau Desktop

Resolution

Follow along in the sample packaged workbook found in the Attachments section for how to sort correctly for each state. In our example, we have focused our data on California and Nevada only.

Option 1
Add multiple layers of geographic data to a map, and sorting can be set up for each state.
User-added image

1. Add Longitude (generated) to Columns and Latitude (generated) to Rows.
2. Add Country/Region and State/Province to Detail. Change the mark type to Pie.
3. Create a calculated field and name it Sub-Category for California.
IF [State/Province]="California" THEN [Sub-Category] END
4. Create a calculated field and name it Sales for California.
IF [State/Province]="California" THEN [Sales] END
5. Add Sub-Category for California to Color.
6. Add SUM(Sales for California) to Angle.
7. Right-click Sub-Category for California in Color and select Sort. Configure it as follows.
 User-added image
8. Right-click State/Province in the Data pane and select Add to New Layer.
9. Create a calculated field and name it Sub-Category for Nevada.
IF [State/Province]="Nevada" THEN [Sub-Category] END
10. Create a calculated field and name it Sales for Nevada.
IF [State/Province]="Nevada" THEN [Sales] END
11. Add Sub-Category for Nevada to Color.
12. Add SUM(Sales for Nevada) to Angle.
13. Right-click Sub-Category for Nevada in Color and select Sort. Configure it as follows.
 User-added image

Option 2
You can specify which state to sort by using a parameter.
User-added image

1. Add Longitude (generated) to Columns and Latitude (generated) to Rows.
2. Add Country/Region and State/Province to Detail. Change the mark type to Pie.
3. Add Sub-Category to Color.
4. Add SUM(Sales) to Angle.
5. Create a parameter and name it Sort by. Right-click Sort by in the Data pane and select Show Parameter.
 User-added image
6. Create a calculated field and name it Sales for Sort.
IF [State/Province]=[Sort by] THEN [Sales] END
7. Right-click Sub-Category in Color and select Sort. Configure it as follows.
 User-added image

Cause

If all pie charts are color-coded by the same dimension, they are sorted by the aggregated result of measure values for all data.
Did this article resolve the issue?