Power BI provides two main types of sortings – ascending and descending. Ascending sort orders the data from lowest to highest (A to Z, or 0 to 9). And, descending sort does the opposite.
To sort a table, follow these steps:
- Select a visual on a report.
- Next, select the Ellipses (…) in the upper-right part of the visual.
- Select the Sort ascending or Sort descending option.
Remember that when a data is not sorted explicitly, Power BI secures the order from the data source.
II. Advanced Sorting Applications in Power BI
While the basics cover most day-to-day requirements, Power BI offers more complex sorting mechanisms for advanced analyses.
1. Sorting by Columns
In Power BI, you can sort tables based on data in one or more columns.
Example:
If you have a Sales table with “Product” and “Revenue” columns, you can sort the table by “Revenue” to see the best-performing products.
2. Sorting By a Different Column
Power BI also lets you sort one column using the values in another one.
Example:
If you have a Month column (January, February, etc.) and want to sort it not alphabetically, but as per its order in a year, you can have another column with month numbers. Then, you can apply sorting based on the sequence of month numbers.
3. Sorting Using ‘Sort by Column’ Feature
This feature comes handy when you want to sort textual data in a non-alphabetical order.
Example:
You have a “Rating” column with values High, Medium, and Low. In a typical ascending sort, ‘High’ would come first, but logically ‘Low’ should come first. Using ‘Sort by Column’ feature, you can associate each rating with a number (High=3, Medium=2, Low=1) and sort accordingly.
III. Creating Custom Sorting Orders in Power BI
For creating custom sorting orders in Power BI, you need to create a separate table with the desired sorting order, and use it for your sorting requirements.
Example:
You might want to create a weekday table where you list weekdays in your desired sort order. Then, you can use this table to sort your other data like sales data for weekdays.
IV. Sorting Limitations in Power BI
In DirectQuery mode, more sorting limitations exist than in Import mode. Also, if a column you sort has ‘Don’t summarize’ option selected, Power BI sorts only the first 2,147,483,647 values.
Now, as an aspiring Microsoft Power BI Data Analyst, remember that mastery of sorting techniques is key for data analysis. Practice extensively with different kinds of data and maximize your understanding of how best to use sorting for revealing hidden patterns.
Finally, remember, sorting is a dynamic process that may require continuous adjustments, depending on the data updates and your evolving analytical needs. That’s why constantly refining these skills is essential.
Practice Test
True/False: Sorting data in Power BI can be automated using either ascending or descending order.
- True
- False
Answer: True
Explanation: Power BI provides the capability to sort data in both ascending and descending order and this can be automated to facilitate data analysis and visualization.
Which of the following functions is used to sort the data in Power BI?
- a) SORT
- b) ORDER
- c) ARRANGE
- d) None of the Above
Answer: d) None of the Above.
Explanation: Power BI does not use functions to sort data. You can sort the data using the functionality in the Visual level, Page level, and Report level filters.
True/False: You can only sort data based on one column at a time in Power BI.
- True
- False
Answer: False.
Explanation: Power BI allows for multi-column sorting. You can sort by more than one column using the “Sort Ascending By” or “Sort Descending By” options from the more options (…) menu in the column headers.
True/False: In Power BI, sorting is only possible in tables and matrix visuals.
- True
- False
Answer: False.
Explanation: In addition to tables and matrix visuals, you can also apply sorting to charts, graphs, and other visuals in Power BI.
In Power BI, how can you perform a multi-column sort?
- a) By dragging multiple columns to the Sort field well.
- b) By selecting multiple columns and choosing Sort.
- c) By using multiple Sort functions.
- d) None of the above.
Answer: a) By dragging multiple columns to the Sort field well.
Explanation: You can perform a multi-column sort in Power BI by dragging multiple columns to the Sort field well in the order that you want the data to be sorted.
True/False: Using the SORT BY COLUMN function in Power BI, you can sort one column based on the values in another column.
- True
- False
Answer: True
Explanation: The Power BI DAX SORT BY COLUMN function enables you to sort one column based on the values in another column.
What is a potential limitation of sorting in Power BI?
- a) You can only sort alphabets, not numbers.
- b) Sorting can be slow if you have a large dataset.
- c) You can’t sort dates.
- d) You can’t sort on calculated columns.
Answer: b) Sorting can be slow if you have a large dataset.
Explanation: Power BI sorts data efficiently, but performance might be affected when sorting large datasets.
Which of the following is a way to perform a descending sort in Power BI?
- a) Right-click and select “Sort Descending”.
- b) In the Sort ascending/descending menu, select the descending option.
- c) Drag and drop the column to the Sort field well and select Descending order.
- d) All of the above.
Answer: d) All of the above.
Explanation: You can sort data in descending order by any of these methods in Power BI.
True/False: You can only sort data in Power BI before creating a visual.
- True
- False
Answer: False.
Explanation: You can sort data in Power BI both before creating a visual and after, by using the built-in sorts in the visualization pane.
Which steps are required to perform a sort operation in Power BI?
- a) Select Sort By Column.
- b) Select the column to sort.
- c) Execute the sort.
- d) All of the above.
Answer: d) All of the Above.
Explanation: To perform a sort operation, you need to select the Sort By Column option, choose the column to sort, and execute the sort.
True/False: You can sort data by a column that is not included in the visual in Power BI.
- True
- False
Answer: False.
Explanation: Although Power BI is very flexible in terms of sorting, you cannot sort data by a column that is not included in your visualization.
What does the term ‘sorting context’ refer to in Power BI?
Answer: The sorting context in Power BI refers to the order in which data is presented, often within a visual, based on values, names, or other factors.
Explanation: Understanding the sorting context is important to best present data in a meaningful and understandable way.
Interview Questions
What is the essence of applying sorting in Power BI?
Applying sorting in Power BI helps to organize data in a particular order, either ascending or descending. This aids better visualization and understanding of data and facilitates decision-making based on data analysis.
How can you sort data in Power BI?
You can sort data in Power BI by selecting the particular column you wish to sort and clicking either “Sort ascending” or “Sort descending” from the column tools in the toolbar.
What is the default sorting option in Power BI?
The default sorting option in Power BI is ascending order.
Can we sort visualizations in Power BI?
Yes, sorting can be applied not only to data directly but also to visualizations in Power BI for better data interpretation.
Is it possible to sort by multiple columns in Power BI?
Yes, Power BI supports multi-column sorting. You can do this by holding down the Shift key and selecting the columns you want to sort by.
Can you apply sorting to a matrix visualization in Power BI?
Yes, you can apply sorting to a matrix visualization in Power BI. To do this, select the matrix and then click on the “More options” button (…) in the upper-right corner of the visualization. Then, select “Sort ascending” or “Sort descending”.
What is the function of sorting data within a specific range?
Sorting data within a specific range helps to filter and focus on particular aspects of the data. It helps to examine a subset of the data closely for thorough analysis.
Can you remove sorting in Power BI?
Yes, you can remove sorting in Power BI by selecting “Don’t sort” from the “Sort ascending” or “Sort descending” options.
What is sorting by a column not in a visual?
Sorting by a column not in a visual allows you to determine the order of items in your visual based on a column that is not part of the visual itself.
How can the sorting order be changed in Power BI?
The sorting order can be changed in Power BI by clicking on the column name again. For example, if the sort order is ascending, clicking on the column name again will change the sort order to descending.
What does ‘Sort ascending’ and ‘Sort descending’ mean in Power BI?
‘Sort ascending’ in Power BI orders the selected column from smallest to largest value, or from A to Z when dealing with text data. ‘Sort descending’, on the other hand, orders the column from largest to smallest, or from Z to A when dealing with text data.
Can you sort data in Power BI using DAX?
Yes, you can sort data in Power BI using DAX (Data Analysis Expressions). It is commonly used in situations where complex sorting methods are required.
How can you apply a sort by column action in Power BI?
To apply a sort by column action in Power BI, go to the “Modeling” tab in the Power BI Desktop, then select “Sort by column” in the “Properties” group.
How can you create a custom sorting order in Power BI?
You can create a custom sorting order in Power BI by creating a separate column that defines your preferred ranking, then using the “Sort by column” feature to sort based on this custom column.
How does hierarchical sorting work in Power BI?
Hierarchical sorting in Power BI sorts the data based on a multiple-column hierarchy. For example, if you select to sort data by “Year” and then by “Month”, the data will be sorted first by the Year and then by the Month within each Year.