Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power BI Table Sort by Column: How to Use Hidden Columns

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To sort a Power BI table by a hidden column, select the column you want to display in the Data view, go to the Column Tools tab, click Sort by Column, and select the hidden numeric or date column that contains the correct sorting order. This achieves a custom sort—such as ordering months chronologically (January, February, March) rather than alphabetically (April, August, December)—while keeping the auxiliary sorting column invisible to the end user in the final report.

What You'll Need

  • Power BI Desktop installed on your machine.
  • A dataset already loaded into your model.
  • A "Sort Column": This is a column in the same table that contains a numeric value corresponding to the desired order of the text column (e.g., a "Month Number" column with 1 for January, 2 for February, etc.).

Step-by-Step

  1. Open the Data View: On the left-hand navigation pane of Power BI Desktop, click the Data icon (the table grid icon). This allows you to see the raw rows and columns of your dataset. Note that menu labels may differ slightly depending on your specific version or region of Power BI Desktop.
  2. Identify Your Columns: Locate the table containing the data. You should see the column you want to display (the "Display Column", such as Month Name) and the column you want to use for sorting (the "Sort Column", such as Month Number).
  3. Select the Display Column: Click on the header of the column that you want the users to see in your report. This highlights the column and activates the context-specific menu in the top ribbon.
  4. Access Column Tools: Once the display column is selected, look at the top ribbon menu. A tab labeled Column Tools will automatically appear. Click on this tab.
  5. Apply the Sort: Within the Column Tools ribbon, locate the "Sort by Column" button. Click this button to open a dropdown menu listing all other columns available in that specific table.
  6. Choose the Hidden Column: From the dropdown list, select the numeric or date column that represents the correct logical order. For example, if you have selected "Quarter Name", you would now select "Quarter Number".
  7. Verify the Sort in Data View: You will notice that the table in the Data view may rearrange itself. The display column is now logically linked to the sort column.
  8. Build Your Visual: Switch back to the Report view (the chart icon on the left). Drag your display column into a Table or Matrix visual.
  9. Finalize the Visual Sort: Click the three dots (More options) in the top right corner of your visual, select Sort axis, and choose your display column. Because you have set the "Sort by Column" property, Power BI will use the hidden numeric values to order the text, but it will only show the text labels to the user.

Common Mistakes

One of the most frequent errors is attempting to sort a column by another column that is located in a different table. Power BI requires both the display column and the sort column to reside within the same physical table. If your sorting logic is in a separate lookup table, you must first bring that sorting value into the main table using a DAX calculated column or by merging the queries in Power Query Editor.

Another common mistake is the "Circular Dependency" error. This happens when you try to sort Column A by Column B, but Column B is already calculated based on Column A. This creates a logical loop that Power BI cannot resolve. To fix this, ensure the sort column is a static value or a simple calculation that does not rely on the column it is intended to sort.

Users also frequently forget to actually set the visual sort. Even after configuring the "Sort by Column" property in the Data view, a visual might still default to sorting by a different measure (like total sales) or alphabetically. You must manually tell the visual to sort by the display column to trigger the hidden sort logic.

Tips

For those dealing with custom fiscal years that do not start in January, create a custom index column in Power Query. By adding an Index Column (starting from 1) after sorting your data in the Power Query Editor, you create a perfect sorting key that reflects your specific business calendar regardless of standard calendar rules.

If you have a small list of custom categories (e.g., "Low", "Medium", "High"), you can create a conditional column in Power Query. Use the "Conditional Column" feature to assign 1 to Low, 2 to Medium, and 3 to High. This is much cleaner than trying to manage complex DAX formulas for simple categorical sorting.

To keep your fields pane organized, you can hide the sort column from the Report view. Right-click the sort column in the Fields pane and select "Hide in report view". This prevents other report builders from accidentally using the numeric sort column in a visual, ensuring they only use the clean, formatted display column.

Troubleshooting

If the sort does not seem to be working, first check the data types. The sort column must be a numeric data type (Whole Number or Decimal) or a Date type. If the sort column is formatted as Text, Power BI will sort it alphabetically (meaning "10" would come before "2"), which defeats the purpose of a hidden sort column.

If you encounter the "Circular Dependency" error mentioned earlier, the safest fix is to go back to Power Query Editor. Create the sort column as a physical column during the data transformation phase rather than using a DAX calculated column. Columns created in Power Query are processed before the DAX engine, which usually eliminates dependency loops.

If the visual is still not sorting correctly, check if there are multiple values in the sort column for a single value in the display column. For example, if "January" is associated with both the number 1 and the number 13 in your sort column, Power BI will not know which one to prioritize, and the sort may appear erratic or fail to apply.

Frequently Asked Questions

Can I sort by a column that is in a different table?

No, the Sort by Column feature only works for columns within the same table. You must use Power Query to merge the tables or DAX to create a calculated column to bring the sort value into the display table.

Why is my table sorting 1, 10, 11, 2, 3 instead of 1, 2, 3?

This happens because your sort column is set to a Text data type. Change the data type of the sort column to Whole Number in the Column Tools tab or Power Query Editor to fix the numerical sequence.

Does sorting by a hidden column increase the file size?

Adding a numeric sort column adds a small amount of data to your model, but the impact is negligible for most datasets. The performance benefit of having a correctly sorted report far outweighs the minimal storage cost.

Can I use this for sorting custom status labels like "Pending", "In Progress", and "Completed"?

Yes. This is the primary use case for this feature. Create a numeric column where Pending = 1, In Progress = 2, and Completed = 3, then sort the status label column by that numeric column.

Will this sort persist if I publish the report to the Power BI Service?

Yes, the "Sort by Column" property is a metadata setting tied to the model. Once configured in Power BI Desktop and published, the sorting logic will remain active for all users viewing the report online.