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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Analitika
Post Prodigy
Post Prodigy

Can't sort year week column in Power BI

Hello,

 

I can't sort year week column in Power BI. I am getting this:

Analitika_0-1653389878339.png

the order is wrong -2 should be before 19 not after. So how to fix it?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Analitika ,

May I know the field in your screenshot is a fact field or a calculated column? If it is a calculated column, could you please provide the related formula? Otherwise, you can create new calculated column as below and sort the new calculated column.

 

Column 2 = 
VAR _position =
    IFERROR ( SEARCH ( "-", 'Table'[Column], 1, 0 ), 0 )
VAR _week =
    MID ( 'Table'[Column], _position + 1, LEN ( 'Table'[Column] ) - _position )
RETURN
    IF (
        VALUE ( _week ) < 10,
        LEFT ( 'Table'[Column], 4 ) & "-0" & _week,
        'Table'[Column]
    )

 

yingyinr_0-1653618435074.png

In addition, you can refer the following links to get it.

Sort a Column with a Custom Order in Power BI

1. Create a sort dimension table
yingyinr_1-1653618641474.png

2. Create a relationship between sort dimension table and fact table

yingyinr_0-1653619030326.png

3. Sort by column EnglishEducation (groups)

yingyinr_4-1653618906225.png

Custom sort orders in Power BI

Power Query Custom Sort

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Analitika ,

May I know the field in your screenshot is a fact field or a calculated column? If it is a calculated column, could you please provide the related formula? Otherwise, you can create new calculated column as below and sort the new calculated column.

 

Column 2 = 
VAR _position =
    IFERROR ( SEARCH ( "-", 'Table'[Column], 1, 0 ), 0 )
VAR _week =
    MID ( 'Table'[Column], _position + 1, LEN ( 'Table'[Column] ) - _position )
RETURN
    IF (
        VALUE ( _week ) < 10,
        LEFT ( 'Table'[Column], 4 ) & "-0" & _week,
        'Table'[Column]
    )

 

yingyinr_0-1653618435074.png

In addition, you can refer the following links to get it.

Sort a Column with a Custom Order in Power BI

1. Create a sort dimension table
yingyinr_1-1653618641474.png

2. Create a relationship between sort dimension table and fact table

yingyinr_0-1653619030326.png

3. Sort by column EnglishEducation (groups)

yingyinr_4-1653618906225.png

Custom sort orders in Power BI

Power Query Custom Sort

Best Regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.