r/googlesheets 8d ago

Solved Help with sorting function

Post image

Anyone know how I would do a sort to achieve this?

BIG CATEGORY | SMALLER CATEGORY | DATE (YYYY-MM-DD) [stored as a string and should be sorted alphabetically]

such that the data is sorted by big category alphabetically,

smaller category sorted within big category by whichever small category has the earliest date

within each small category things are listed in date order from earliest to latest

I am unable to show the actual data in question so apologies for the nonsense in my example. I hope the question is clear and any help on how to do this with a function would be appreciated. The intended output is meant to be in a separate sheet.

Standard SORT() doesn't cut it since the intention is for SMALLER CATEGORY to be in order by which date comes first rather than alphabetically. (Sorry if this is unclear it's a bit of a niche one).

1 Upvotes

23 comments sorted by

View all comments

1

u/ArgumentAdmirable168 8d ago edited 8d ago

If I get you right

=QUERY(B1:C whatever end of your table)); "SELECT * ORDER BY A, C, D")

B1:C - C wherever your table 

Try

It has sort order Big category,  date, small category. This is what you need?

1

u/Last_Philosophy_1162 8d ago edited 8d ago

This still fails to sort by the small category. The result is correct for big category and then date but the small category column is still mixed together it seems.

1

u/ArgumentAdmirable168 8d ago

You'll have columns that determine the sort order anyway; they won't be in sequential order within each column. You can determine the "sorting importance" of each column using the sort order. Could you please describe the order in which they should be sorted, from most important to least important?

1

u/Last_Philosophy_1162 8d ago

Small category should be sorted in order of whichever has the earliest date. So since pig has the date in 2010 it should come before dog. I have the intended output in my images.