+ Reply to Thread
Results 1 to 14 of 14

Power Query - Dates not sorting in output

  1. #1
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Power Query - Dates not sorting in output

    I have Power Query setup in the attached that has a sort on the dates within the query that shows the sort correctly as does the preview when you hover the mouse over the query pane, yet when the data is loaded to a table it seems to be in a different sort order until you sort the data in the output table as an additional step.

    I know you can workaround this by sorting in the output and preserving the table sort, but is there something I'm missing?
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Power Query - Dates not sorting in output

    What are you doing with the data in PowerQuery?

    In your example workbook if I remove the Changed Type step the data is sorted correctly when it's returned to the sheet.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    But when I do that I get a Date & Time in the output. I can see the sort is now correct, but it still needs me now to change the cell format outside of Power Query.

    The idea is that all my formatting of cells and sorting is done with one step, ie. Power Query.

    Like I said the preview output is correct, just not the actual output.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Power Query - Dates not sorting in output

    Move Changed Type after Sorted Rows

  5. #5
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    Still the same result for me.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Power Query - Dates not sorting in output

    I don't know what you have done - if I recreate the query from scratch, it works. See far right in the attached file.
    Attached Files Attached Files
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    That's strange.

    When I open your file and try and edit your query I get this warning message.

    Capture.JPG

    And if I try and refresh my query in that same book I get this error message.

    Capture2.JPG

    Maybe it's my version of Power Query? My update button is greyed out.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Power Query - Dates not sorting in output

    That will be because I have Office 365 - sorry. Here's the M code:

    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Date", Order.Ascending}})
    in
    #"Sorted Rows"

  9. #9
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    Code looks exactly the same as mine.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Power Query - Dates not sorting in output

    Can you check that your copy of Excel 2016 is fully patched? A quick Google suggests there may have been a sorting bug in PQ and Power Pivot in Excel 2016, but bugs should be fixed in updates.

  11. #11
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    I'm using 2013 with PQ.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Power Query - Dates not sorting in output

    OK, well no idea, then - sorry. What happens if you recreate the query from scratch?

  13. #13
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Power Query - Dates not sorting in output

    It's inherent in all of the queries I write. No matter how I do the sorting within the query, it is not reflected outside of the query without applying the sort to the output table and preserving the sort in the table properties.

    Extra steps that I'm hoping to avoid.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Power Query - Dates not sorting in output

    Ah, OK - that explains it. In newer versions of PQ you don't need to do that, as it is done for you by default. In your older version you have to tick to preserve the sort order in table properties. This was fixed quite recently - I remember another thread about it - I think it was between myself and Dominic. Must have been 6-9 months ago - what you have just said has jogged my memory. Looks like the only way to avoid the extra step will be to upgrade.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Power Query Sorting by Date not sorting correctly
    By kersplash in forum Excel General
    Replies: 5
    Last Post: 08-20-2018, 02:59 AM
  2. [SOLVED] Power Query - want to add formulas to query output
    By kersplash in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 07-19-2018, 06:16 AM
  3. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM
  4. Power Query - Sum between dates formula explanation
    By AZ-XL in forum Excel General
    Replies: 1
    Last Post: 04-03-2018, 03:20 AM
  5. Power Query and adding a column changing dates
    By ammartino44 in forum Excel General
    Replies: 0
    Last Post: 01-09-2018, 05:24 AM
  6. Power Query Duration Between Two Dates
    By mielkew27 in forum Excel General
    Replies: 3
    Last Post: 04-18-2017, 01:31 AM
  7. Power Query - Add dates to fixed Data set
    By happydays886 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2017, 10:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1