Sorting data by one column primarily and then by another column regardless of the first sort column value.

Anonymous
2023-02-04T22:55:44+00:00

Hi,

I have an Excel file that has lots of rows with some rows largely repeats of other rows. I have a high-priority column I sort the file on, let's call it "job cancel date," and then I have another column of interest, say "site address." I want to be able to sort the file on "job cancel date" primarily, with most recent (ie, largest) first, and then if there are other rows later on in the file that have the same "site address" as a row with a larger "job cancel date" I want those rows to be located immediately under the first row having that "site address" with the larger "job cancel date," with those later rows (having the same "site address") arranged by "job cancel date" under the first row having that "site address." How can I do that?

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Ashish Mathur 101K Reputation points Volunteer Moderator
    2023-02-07T02:53:22+00:00

    Hi,

    Enter this formula in cell D2

    =SORTBY(A2:B5,B2:B5,1,A2:A5,-1)

    Hope this helps.

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Ashish Mathur 101K Reputation points Volunteer Moderator
    2023-02-05T00:01:05+00:00

    Hi,

    You should always post some data (in a format the can be pasted in an MS Excel file) and show the expected result. Anyways, use the SORT()/SORTBY() function.

    0 comments No comments
  2. Anonymous
    2023-02-07T00:01:49+00:00

    Hi Ashish,

    I don't know how to do any of what you're saying. All I know how to do is this: Image

    ... and it doesn't do what I want.

    Here's some data ...

    cancel date site address
    11/25/2022 A
    11/25/2022 B
    11/25/2022 C
    10/23/2022 A

    What I want to have happen is for the sort of this entire table to be primarily by cancel date, as shown, and then if there exists another site address that matches a more recent cancel date site address for that to be right under the latest one, like this...

    cancel date site address
    11/25/2022 A
    10/23/2022 A
    11/25/2022 B
    11/25/2022 C
    0 comments No comments
  3. Anonymous
    2023-02-07T04:01:00+00:00

    Ashish,

    I appreciate that you have probably given me the answer. However, the actual file I'm "working" with is massive, with many upon many columns and thousands of rows, being drawn from another worksheet by formulae that I haven't a clue how to interact with. I was hoping there was a solution that wouldn't involve modifying the file at all.

    Thanks.

    0 comments No comments
  4. Ashish Mathur 101K Reputation points Volunteer Moderator
    2023-02-07T04:17:02+00:00

    You are welcome. The standard sort operation (shown your screenshot earlier) should work fine

    0 comments No comments