Share via

Excel SORT/SORTBY function

Henn Sarv 46 Reputation points
2026-03-01T19:41:07.3333333+00:00

Nice to have possibility to allow negative numbers in SORT sorting array - meaning sort order

=SORT(array;{3;-2;5;-1})
equals
=SORTBY(array;chooscol(array,3;1;2;-1;5;1;1;-1))

I know that with REDUCE I can create this but compact SORT might perform better

Thanks
[Moderators note: personal information removed]

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dana D 0 Reputation points
    2026-03-04T01:25:54.9966667+00:00

    equals =SORTBY(array;chooscol(array,3;1;2;-1;5;1;1;-1))

    I know that with REDUCE I ca

    ..It can only takes a single sort_index and sort_order.

    = = = = = = = = =

    Hi. Just so you know, the A.I. bots are not totally correct.

    =SORT(A1:B7,{1,2},{-1,1})

    You should NOT use Sortby, and Reduce is not the best option either.

    0 comments No comments

  2. Hendrix-C 12,120 Reputation points Microsoft External Staff Moderator
    2026-03-01T20:32:42.2566667+00:00

    Hi @Henn Sarv,

    Thank you for posting your question in the Microsoft Q&A forum.

    I greatly appreciate your idea as currently SORT() does not support multi-key sorting with mixed directions encoded in the sort_index part. It can only takes a single sort_index and sort_order. The current approach fo mixed acsending/descending across multiple columns is using SORTBY() with order pairs as your example.

    While this feature is not available today, I'm optimistic about future enhancements. I strongly recommend you share your great ideas directly with the Microsoft engineering team via Microsoft 365 Feedback Hub → Send Feedback and describe your suggestion in detail. Your input plays a vital role in shaping the future of Microsoft products.    

    User's image

    Note: As community moderators, I kindly ask for your understanding that my access to internal development details is limited. My primary role is to guide users toward the appropriate resources and support channels. While I may not have influence product design decisions and have limited access to internal development details, I'll continue doing our best to support you within the scope of my responsibilities.      

    Thank you for your understanding and corporation. If you have any concerns or questions in the future, please don’t hesitate to reach out. Not only will I be happy to assist you, but all moderators in the Q&A forum will also do their best to provide support and guidance.  

    Thank you for being a valued customer and for contacting us on the Microsoft Q&A forum.  

    Wishing you a wonderful day ahead.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".       

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments

  3. Q&A Assist
    2026-03-01T19:41:18.5733333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Excel SORT does not support an array of sort indexes or negative column indexes in the way described. The documented syntax is:

    =SORT(array, [sort_index], [sort_order], [by_col])
    

    where sort_index is a single number (one row or column to sort by), and sort_order is a single number (1 or -1). There is no built‑in option to pass something like:

    =SORT(array, {3;-2;5;-1})
    

    to represent multiple keys and sort directions.

    For multi-key sorting based on other ranges/arrays, the supported approach is to use SORTBY, whose syntax is:

    =SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2], …)
    

    This allows multiple sort keys and independent sort orders, but each by_array must be a valid one-row or one-column range/array; negative indexes or CHOOSECOL-style index lists are not part of the function’s design.

    To achieve complex multi-column sorting today, the supported options are:

    • Use SORTBY with explicit by_array arguments and sort_order values (1 or -1) for each key.
    • Use helper arrays (e.g., via CHOOSECOLS, REDUCE, etc.) to construct the by_array inputs, then feed them into SORTBY.

    The requested compact SORT syntax with mixed positive/negative indexes is not available in the current documented behavior of SORT or SORTBY.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.