Trying to Sort by two different columns while using the FILTER function.

Wright, Paul@CHP 5 Reputation points
2025-12-11T16:18:10.5166667+00:00

I am currently sorting by one column (see below) and it is working as needed.

=SORT(FILTER('Score Calculations'!B9:Q38,('Score Calculations'!E9:E38>44)*('Score Calculations'!F9:F38>44),""),16,-1)

User's image

Here is the source sheet:

User's image

Here is the new formula I am trying to use that is not working, just returning "#VALUE!"

=SORTBY(FILTER('Score Calculations'!B9:Q38,('Score Calculations'!E9:E38>44)*('Score Calculations'!F9:F38>44),""),'Score Calculations'!Q9:Q38,-1,'Score Calculations'!K9:K38,-1)

What am I doing wrong?

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

Answer accepted by question author
  1. Hendrix-C 8,560 Reputation points Microsoft External Staff Moderator
    2025-12-11T17:00:27.08+00:00

    Hi @Wright, Paul@CHP,

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

    Based on your sharing, the reason you had #VALUE! error is because the structure of SORTBY formula is: SORTBY(array, by_array1, sort_order1, [by_array2, sort_order2], ..) and it needs each array part is in the same height as the array you're sorting. In your formula:

    • You use FILTER to returns the rows that meet E>44 and F>44. I assume about 16 rows meet that condition
    • The sort keys you use are Q9:Q38 and K9:K38 which are always considered as 30-row ranges
    • That's why when SORTBY tried to sort the 16-row array using 30-row by_array keys, the height is different so the function returns error.

    Therefore, you need to point your sort keys to columns inside the filtered array. I suggest you can try this formula:

    =LET(f,FILTER('Score Calculation'!B9:Q38,('Score Calculation'!E9:E38>44)*('Score Calculation'!F9:F38>44),""),SORTBY(f,INDEX(f,,16),-1,INDEX(f,,11),-1))
    

    Hope this information proves helpful. You can try this formula and let me know if it works for you. If not, we can work together to find a solution.

    Thank you for your understanding and cooperation. If you have any questions or need further assistance, please feel free to share them in the comments so I can continue to support you.

    I'm looking forward to your reply.


    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Dana D 0 Reputation points
    2025-12-12T13:56:17.5133333+00:00

    Hi. I see you have a solution. This will probably be ignored, but... since you showed interest..

    Just to let you know, SORTBY is not the appropriate function to use. It makes it more complicated.

    Instead of your common solution of:

    SORTBY(f,INDEX(f,,16),-1,INDEX(f,,11),-1)

    I would recommend the following:

    SORT(f,{16,11},{-1,-1})

    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.