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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Aksgr
New Member

Unable to sort date in chronological order

Hi all ,

I have dates (entire calender ) as columns hence i would have 365 collums. But they look jumbelled and I want it in chronological order.

 

I have attached the Screenshot please do take a look and help

 

WhatsApp Image 2023-02-04 at 21.50.38.jpg

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Aksgr ,

 

According to your screenshot, I know that your dates are in column headers. As far as I know, in this situation, Power BI will sort those column headers like text data. So 25/02/2023 will be considered smaller than 30/01/2023. 

RicoZhou_2-1675669726466.png

Here I suggest you to unpivot those date columns and do some transormation to get a date column in date format.

RicoZhou_0-1675669330923.png

Whole code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYmMgNgVicyC2VIrViVZyArKMgNgEiM2A2AKk0kApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, #"01/01/2023" = _t, #"30/01/2023" = _t, #"01/02/2023" = _t, #"15/02/2023" = _t, #"28/02/2023" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"01/01/2023", Int64.Type}, {"30/01/2023", Int64.Type}, {"01/02/2023", Int64.Type}, {"15/02/2023", Int64.Type}, {"28/02/2023", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Category"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", Int64.Type}, {"Attribute.2", Int64.Type}, {"Attribute.3", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Attribute.1", "Day"}, {"Attribute.2", "Month"}, {"Attribute.3", "Year"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Date", each #date([Year],[Month],[Day])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type date}})
in
    #"Changed Type2"

 

Result is as below.

RicoZhou_1-1675669675301.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Aksgr
New Member

Hi @selimovd  Thankyou for your responce,

 

Unfortunetly its not yet resolved. The issue is that I have column names of each date . Do look at these attached pics. 

WhatsApp Image 2023-02-04 at 22.19.12.jpgWhatsApp Image 2023-02-04 at 22.19.29.jpg

Anonymous
Not applicable

Hi @Aksgr ,

 

According to your screenshot, I know that your dates are in column headers. As far as I know, in this situation, Power BI will sort those column headers like text data. So 25/02/2023 will be considered smaller than 30/01/2023. 

RicoZhou_2-1675669726466.png

Here I suggest you to unpivot those date columns and do some transormation to get a date column in date format.

RicoZhou_0-1675669330923.png

Whole code:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYmMgNgVicyC2VIrViVZyArKMgNgEiM2A2AKk0kApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, #"01/01/2023" = _t, #"30/01/2023" = _t, #"01/02/2023" = _t, #"15/02/2023" = _t, #"28/02/2023" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"01/01/2023", Int64.Type}, {"30/01/2023", Int64.Type}, {"01/02/2023", Int64.Type}, {"15/02/2023", Int64.Type}, {"28/02/2023", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Category"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Attribute.1", "Attribute.2", "Attribute.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", Int64.Type}, {"Attribute.2", Int64.Type}, {"Attribute.3", Int64.Type}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Attribute.1", "Day"}, {"Attribute.2", "Month"}, {"Attribute.3", "Year"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Date", each #date([Year],[Month],[Day])),
    #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom",{{"Date", type date}})
in
    #"Changed Type2"

 

Result is as below.

RicoZhou_1-1675669675301.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

selimovd
Super User
Super User

Hey @Aksgr ,

 

if the column is from the type Date or DateTime, then it should automatically sort correctly.

Otherwise for the month name you have to set a sort by column:

https://learn.microsoft.com/power-bi/create-reports/desktop-sort-by-column

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic

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 Solution Authors
Top Kudoed Authors