How to Sort Data in Q
Sorting data can assist you to understand, analyze, and visualize it. In Q, sorting is most often done to improve the way tables or charts communicate the results, but sorting can also be applied to help you check raw data. In this article we look at ways to sort your tables and charts including ways to automate this process as well as sorting the raw data.
Sorting tables manually
On a table there are three ways to manually sort the data. You can drag rows or columns manually, or you can sort the rows and columns based on the current values of a table statistic or their labels.
Dragging and dropping rows in the table is appropriate if you just need to make a few changes. However, if you need to reorder a whole table, the built-in table sort function is more efficient. Consider the following technology brand ratings table. The default sort in this case is the initial order of the brand variables as they were shown in the questionnaire.
With the built-in function, you can sort by labels or values. To sort by the brand names in alphabetical order, right-click on a row header and select Sort by > Labels – Ascending. To sort the brands in descending order according to the average brand rating, right-click on the column header and select Sort by > Values – Descending > Average. Note that you can sort by any of the available cell statistics that are currently being displayed in the table.
Sorted Ascending by Labels (Brands) Sorted Descending by Brand Rating (Average)
Some additional table sorting functions can be found in the Automation menu in Q. These automated functions include various Rules that provide additional functionality and flexibility beyond the basic sorting options in Q. Most of the sorting functions can be found under the menu Automate > Browse Online Library > Sorting and Reordering.
By definition, a Rule is applied to an individual table in Q. For example, Sort Rows (Automatically Updates when Data Changes) applies a sort to a specific table. The options allow you to set specific parameters such as which column to sort by, the sort order and rows to include/exclude from the sort operation.
As the name indicates, the sort will execute again automatically when the underlying data is changed or updated.
How to sort charts
When displaying a table as chart in Q, the chart will adopt whatever sort order was applied to the table, whether applied manually or by an automated sorting function. Take the previous example where we sorted technology brands by likelihood to recommend. When changed to a bar chart using View > Show Data as > Bar Chart, the chart is sorted in descending order just as the table was.
Sorting in the Data tab
You can also sort in the Data tab, which can assist when you need to check the raw data. In Q, you never modify the underlying data file, and so any sorting is stored in the project file. For this reason, Q requires that a unique identifier be set before data sorting can be enabled. You can do this using the Case IDs dropdown box under the menus in the Data tab.
Once the identifier has been set, you can sort by any column by right-clicking on the column header and select one of the sorting options: Sort Data by This Column – [Ascending | Descending].
Now that your data has been sorted, we bet you’re ready to move on to doing more in Q! Check out Using Q.