Sort one column by another column in Power BI
In this exercise, we will learn how to define the sort order of column by another column in the table.
The following table is the data that we are using for the demonstration.
Month No | Salary | Month |
---|---|---|
1 | 17000 | Jan |
2 | 20000 | Feb |
3 | 14000 | Mar |
4 | 45000 | Apr |
5 | 76568 | May |
6 | 32445 | Jun |
7 | 34568 | Jul |
8 | 76457 | Aug |
9 | 98578 | Sep |
10 | 90657 | Oct |
11 | 24678 | Nov |
12 | 20570 | Dec |
Step 1: Let’s create a visual with Month and Salary column from the table. In the X-axis we have Month column, and, in the Y-axis, we have the Salary column.
We can see from the visual, that the months are being sorted alphabetically: Apr, Aug, Dec, Feb, and so on. However, we want them to be sorted chronologically i.e. Jan, Feb, Mar and so on.
Step 2: In order to achieve the chronological order, we are using the Month no column of the table. So here what we are going to do, we will sort the Month column on the basis of Month no column of the table.
Step 3: Select the column that we want to sort, in this case, Month column from the table. Note that the months in the visual are sorted alphabetically. In the Fields pane, the Column tools tab becomes active.
Step 4: Select Sort by column tool, then select the field we want to sort the other field by, in this case, Month no.
Now we can see that the visual automatically sorts chronologically by the order of months in a year.
Please note that if the Month column is used anywhere in the report, there is it is automatically sorted by the Month no column. So, we can say that the effect of this Sort by column feature is at the report level.