When creating Queries in Visual Mode, Chartio creates the ORDER BY clause of the generated SQL query by listing the categorical columns in the order that they’re chosen in the Query and sorts each column in ascending order by default. Aggregated columns are not included in the autogenerated query, but you can add them and change the column sort order and directions by editing Query Sort in the Advanced Drawer. For instance, if you wanted to sort by the aggregated column first then by the categorical columns, you could set that in the Query Sort.
You also have a couple other options for performing advanced sorting on your result set.
Switch your chart to SQL Mode and edit the SQL to change the order of the sorted columns in the ORDER BY clause.
Note: Updating the SQL query in SQL Mode will disconnect Visual Mode and SQL Mode for the chart. In other words, making subsequent changes to your dataset in Visual Mode after editing the SQL Mode query will no longer update the auto-generated query in SQL Mode.
Transpose and reorder
- Use Transpose to swap the rows for columns and columns for rows.
- Once transposed, use Reorder Columns to drag your columns (i.e., your rows) in the desired order.
- Finally, add one last Transpose to revert your columns back to rows.