Sort Charts with an X axis by a Measure Value instead of Dimension

Whenever you have a viz with an X axis, the sort of that axis will always be based on the x axis dimension regardless of how the results are ordered by a measure. However, in some cases you may want to sort the results by a measure like your Top 5 Brands by Inventory Sold.

In those scenarios, there is a quick workaround to achieve the desired sorting order as long as you’re sorting < 10 values (see limitations).

Workaround: Concat the row number with the x axis string

  1. Insert a new column
  2. Combine the row number function with your desired X-axis field
  3. Use this new concatenated field as your X-axis.
  4. Sort by your desired measure.

Example Implementation

Let’s say you want to look at your Top 5 brands by inventory sold and show some revenue information like Margin and Total sales. In this case a scatter chart is one solution where you sort by Inventory Volume, size by total sales, and color by Margin.

  1. Sort the results by Total Order Items
  2. Create a new field called “Top Brands” with formula =CONCAT(TEXT(ROW(),"00), '. ', A1) (Note: if you are sorting less than 10 rows you can skip the TEXT() function)
  3. Set Top Brands (rather than Brands) as your X-axis in the chart options
  4. Drag Total Sales to the size section
  5. Drag Total Margin to the color section

The result will show numbered countries on the X-axis, sorted by your chosen measure:

Can work around the string sort using TEXT() with leading 0s, so TEXT(ROW(), “00”) would fill to two digits.

Ah thanks Colin, updated the post!