Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Sort by column does nothing

Hi!

 

I have a workbook with multiple tables that all connects to the same date-table. This date-table contains a special column which is used as axis for all the visuals. However, this axis/column is string so the sorting is not really working as I would like. To solve this I created a sort-column in the date-table but when sorting by this under Modeling > Sort by column nothing happens.

 

Below is a minimalized example of my file.

 

Date-table:

Date               special_axis                            sort_column

2016-12-0320162016
2016-12-0420162016
2016-12-0520162016
2017-01-01January - November 20172017
2017-08-01January - November 20172017
2017-11-30January - November 20172017
2017-12-01December20173000
2017-12-02December20173000

 

The date-column are simply dates imported from excel.

 

Then the special_axis is created using the DAX below:

special_axis = if(YEAR('date'[Date]) < 2017; FORMAT('date'[Date];"YYYY"); // if before 2017 > year only
    if(MONTH('date'[Date]) = 12; Format('date'[Date];"MMMM") & FORMAT('date'[Date];"YYYY"); // elif december 2017 > December 2017
        "January - November " & FORMAT('date'[Date];"YYYY"))) // else > January - November 2017

The sort column:

sort_column = if(len('date'[special_axis]) = 4; VALUE('date'[special_axis]); // if only year > year
    if(len('date'[special_axis]) > 16; VALUE(year('date'[Date])); // elif multiple monhts > year
        3000) ) // else sole month > 3000 (will always be last until year 3001..)

 

Then I have a simple value-table which is connected to the date-table on Date

Date               Value

2016-12-0382
2016-12-0447
2016-12-0521
2017-01-0133
2017-08-0139
2017-11-3036
2017-12-0153
2017-12-0282

 

A simple bar chart looks like this with special-axis on axis and Value in Value.

PBI-sort.PNG

 

 

As you can see the Axis is sorted by the strings in special_axis even though I have selected to sort by sort_column under Modeling > Sort By Column.

 

How to use Sort By Column so it actually sorts by the column I have selected. (As you probably understood the December 2017 should be to the right in the chart.)

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

Try clicking the ellipses in the visual and changing the sort to the Date column? Is your Sort By on the Date column or the Special Axis column?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

By ellipses in the visual you mean the three small dots in the upper right corner of the visual? If so there is not the option sort by  date, only be special axis or Value. 

 

Regarding the second question this is where I get a bit confused. If marking the column Date in the date table on the right and then select Sort By Column it shows a tick next to Date (default). See below:by date.png

 

If marking the column special_axis in the date table on the right and then select Sort By Column it is a tick next to axis_special (default). The same goes for when marking sort_column(order_column). But nothing happens with the visual. 

 

I have also tried to add the Date-column and the order column to the visual´s axis cell, below the axis special. But this doesn´t change anything.

Hi @Anonymous,

 

In your scenario, you should firstly select [special_axis] column, and sort [special_axis] column by [sort_column]. Then it should work as expected like below.

 

r4.PNG

 

However, as both [special_axis] column and [sort_column] are created with DAX and rely on [Date] column, you'll receive an circle dependency error when trying sorting [special_axis] column by [sort_column]. So you'll need to create the two columns in Query Editor with M. Smiley Happy

 

Regards

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors