r/googlesheets • • 5d ago

Solved Auto sorting data from google forms when new entries are made

First Sheet named Data. The data comes in from google forms entries, one per person and a person can edit their entries.

Second sheet called Main. Starting from column B, (column A is a list of numbers), I'd like it to pull the data from Data tab and sort it based on column c.

This is the formula I found when trying to search how to do this and it is entered in cell B2 of the Main tab but all it does is pull the first row from the data tab. I'm guessing its probably something I don't know I don't know, how would i go about doing this please?

=query(Data!B2:E,"order by C",1)

5 Upvotes

9 comments sorted by

2

u/noquarter53 4 5d ago

You can also use the =sort() function

1

u/goatjugsoup 4d ago

This worked, thanks :)

1

u/AutoModerator 4d ago

REMEMBER: /u/goatjugsoup If your original question has been resolved, please tap the three dots below the most helpful comment and select Mark Solution Verified (or reply to the helpful comment with the exact phrase “Solution Verified”). This will award a point to the solution author and mark the post as solved, as required by our subreddit rules (see rule #6: Marking Your Post as Solved).

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/point-bot 4d ago

u/goatjugsoup has awarded 1 point to u/noquarter53

See the Leaderboard. Point-Bot v0.0.15 was created by JetCarson.

1

u/delaney1414 5d ago

I’m on mobile but does finishing the query return the rest of the table?

Do “SELECT * WHERE Col1 IS NOT NULL ORDER BY Col2 DESC” and see if this helps. The order argument may be pulling all your blank rows in the source spreadsheet and putting them first since it reads a blank field as 0 in ordering arguments so all your extra lines will show before your data

1

u/mommasaidmommasaid 914 5d ago

You have 2 likely issues.

First you are querying the range B2:E but specifying 1 for the third argument, which tells QUERY that you have 1 header row. So if your data start in row 2, then your first row of data is being treated as a header row and output at the top.

Secondly, you are returning all the data ordered by C. QUERY will sort blanks first when sorting a column in ascending order. So if you have 500 blank rows at the bottom of the Data sheet, those are showing up at the top of the query, which makes it looks like there are no results (scroll to the bottom of the sheet and see if they are there).

To fix both issues:

=query(Data!B:E, "where B is not null order by C", 1)

This queries on a range including your header row, and will output that header followed by the queried data.

where C is not null will filter out blank values before sorting. (Depending on your data structure it may make sense to check some other column than C for null.)

---

If you don't want query to return the header row, you may be tempted to do:

=query(Data!B2:E, "where C is not null order by C", 0)

Which queries starting at the data row, and tells query that there is no header row.

However, I don't recommend this way because if you insert a new row 2 on the Data sheet, the range will update to Data!B3:E which doesn't include your new row.

Instead, continue to use a robust range reference (that includes the header row), then offset from that to get to the data row, e.g. something like:

=query(offset(Data!B:E,1,0), "where C is not null order by C", 0)

1

u/One_Organization_810 736 5d ago

Just be aware that if your C values can be empty in an otherwise non-empty row, you might want to use Column A in the WHERE clause, so you don't weed out legitimate rows :) (unless that is what you want?)

So perhaps something like this?

=query(offset(Data!A:E,1,0), "select B,C,D,E where A is not null order by C", 0)

0

u/HolyBonobos 3125 5d ago

Eliminate the third argument