To order 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, and select Sort by Column, then choose the hidden numeric column that contains the correct sequence. This allows you to maintain a clean visual presentation while ensuring your data follows a logical order—such as sorting months (January, February, March) rather than alphabetically (April, August, December).
What You'll Need
- A Power BI Desktop project with an existing dataset.
- A table that contains both the descriptive column (the one you want to see) and a corresponding numeric column (the one you want to sort by).
- Administrative permissions to edit the data model in the current .pbix file.
Step-by-Step
- Prepare Your Data Source: Before opening Power BI, ensure your data source (Excel, SQL, etc.) has a sorting key. For example, if you have a column for "Quarter" (Q1, Q2, Q3, Q4), you need a corresponding column for "Quarter Number" (1, 2, 3, 4). If this does not exist, you must create it in Power Query or via a Calculated Column.
- Open the Data View: On the left-hand navigation pane of Power BI Desktop, click the Table view icon (the grid icon). This view allows you to see the raw data and manage column properties more effectively than the Report view.
- Select the Display Column: Click on the header of the column that you want to appear in your visual but which is currently sorting incorrectly. For instance, click on the "Month Name" column. Note that labels and menu paths may differ slightly depending on your version of Power BI Desktop or regional settings.
- Access Column Tools: Once the column is selected, a contextual tab called "Column tools" will appear in the top ribbon. Click on this tab to reveal the data formatting and sorting options.
- Apply the Sort Order: In the Column tools ribbon, locate the "Sort by Column" button. Click the dropdown arrow and select the numeric column that represents the correct order (e.g., select "Month Number"). Power BI will now associate the text values of the first column with the numeric values of the second.
- Build Your Visual: Switch back to the Report view. Drag your display column (e.g., "Month Name") into a Table or Matrix visual. You will notice that the table is now sorted by the hidden numeric values rather than alphabetically.
- Hide the Sort Column: To keep the Fields pane clean and prevent users from accidentally using the numeric column in reports, go back to the Data view or the Fields pane. Right-click the numeric sort column and select "Hide in report view." The column remains in the model to drive the sorting logic, but it is no longer visible to the end-user.
Common Mistakes
One of the most frequent errors is attempting to sort the numeric column by the text column. The logic must always be: Select the column you want to see → Sort by the column that holds the order. If you do this in reverse, you will not achieve the desired visual result in your reports.
Another common mistake is having a "many-to-many" relationship between the display column and the sort column. For the "Sort by Column" feature to work, there must be a 1:1 relationship between the values. For example, if you have "January" appearing multiple times in your data, but it is associated with both "1" and "13" in your sort column, Power BI will trigger a circular dependency error or a "cannot sort" error because it doesn't know which number to prioritize for that specific text string.
Users also often forget to hide the sort column. While not a technical failure, leaving the numeric sort columns visible creates clutter in the Fields pane, making it harder for other report creators to find the actual dimensions they need for analysis.
Tips
If your data source does not come with a sort key, you can quickly create one using a Conditional Column in Power Query. Go to Transform Data > Add Column > Conditional Column. You can manually assign numbers to your categories (e.g., If Column equals 'High' then 1, If Column equals 'Medium' then 2, etc.). This is the safest way to ensure your custom sort order is baked into the data before it ever reaches the visualization layer.
For those working with dates, remember that Power BI has built-in date hierarchies. However, if you are using a custom fiscal year that starts in July, the standard date sort will not work. In this case, creating a "Fiscal Month Number" column (where July = 1, August = 2) is the only way to get your tables to display in the correct corporate sequence.
When working with large datasets, using an integer for your sort column is more performant than using a decimal or a string. Integers are processed faster by the VertiPaq engine, which helps keep your report snappy when filtering through millions of rows.
Troubleshooting
Circular Dependency Error: If you receive an error stating that a circular dependency was detected, it usually means you are trying to sort a calculated column by another calculated column that relies on the first one. To fix this, ensure that at least one of the columns is a static value from your original data source or created in Power Query rather than via DAX.
Sort Order Not Changing in Visual: If you have applied the "Sort by Column" setting but the table still looks alphabetical, check the visual settings. Click the three dots (...) in the top right corner of the visual, select "Sort axis," and ensure the correct column is selected. Also, verify if "Sort ascending" or "Sort descending" is toggled; sometimes the logic is correct, but the table is simply sorted Z-A instead of A-Z.
Missing Sort Column: If the numeric column does not appear in the "Sort by Column" dropdown, check the data type of that column. The sort column must be a data type that Power BI can sequence (typically a Whole Number or Decimal). If it is formatted as "Text," the sort will still be alphabetical, defeating the purpose of the hidden column.
Data Refresh Issues: If you added the sort column in the source file after the report was already built, you must click "Refresh" in the Home ribbon to pull the new column into the model before you can assign it as the sort key.
Frequently Asked Questions
Can I sort by multiple hidden columns?
No, the "Sort by Column" feature only allows you to associate one display column with one sort column. If you need a complex multi-level sort, you should create a single "Composite Key" column in Power Query that combines your sorting criteria into a single numeric value.
Does hiding the column delete it from the model?
No, hiding a column only removes it from the Report view. The column still exists in the data model and continues to perform its function of sorting the display column. It is still included in the file size and memory usage.
Will this work for Slicers as well as Tables?
Yes. Once you set the "Sort by Column" property for a column in the Data view, that logic is applied globally. Any Slicer, Table, Matrix, or Chart that uses that column will automatically follow the hidden sort order.
What is the best way to handle months that repeat across years?
If your table shows months across multiple years, sorting by a simple "Month Number" (1-12) will group all Januarys together regardless of the year. To fix this, create a sort column using a formula like (Year * 100) + MonthNumber. This creates a unique number for every month in history (e.g., 202301, 202302), ensuring a chronological flow.
Can I use a DAX measure to sort a column?
No, you cannot use a measure to drive the "Sort by Column" setting. The sort key must be a physical column in the table. If you need a dynamic sort, you may need to rethink your data architecture or use a calculated column instead of a measure.