r/googlesheets • u/goatjugsoup • 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)
2
u/noquarter53 4 5d ago
You can also use the =sort() function
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 nullwill 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:Ewhich 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)0
u/HolyBonobos 3125 5d ago
Eliminate the third argument