Search code examples
sortinggoogle-sheetsformattinggoogle-sheets-formulagoogle-sheets-query

Sorting Rows By Date Using Query in Google Sheets


This query function is pulling the correct data, but for some reason its still not sorting the rows by date - any suggestions?

Copy of sheet: https://docs.google.com/spreadsheets/d/10LTLrb66F8t3jOPrvtuDs8wCrsSmNPcP953O_IWpjbM/edit?usp=sharing

=QUERY('Zapier Leads'!A2:AA, "SELECT A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, Z, AA, T, U, V, W, X, Y WHERE not A Matches 'selection8_address' order by 6 asc", 1)

enter image description here


Solution

  • You mentioned

    ...not sorting the rows by date

    The issue is that in your query formula at the Master tab you use =QUERY('Zapier Leads'!A2:AA, "....",1)
    This means that you consider the first row as a header.
    As a result cell F2 is NOT formatted as Date.

    Please use the following formula where the issue is fixed.

    =QUERY('Zapier Leads'!A2:AA, "SELECT A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, Z, AA, T, U, V, W, X, Y WHERE A is not null and not A Matches 'selection8_address' order by F")
    

    In addition.

    For your Last7DaysLeads tab you can use this simplified formula.

    =QUERY(QUERY(Filtered!A1:Z,"", 1), "WHERE Col24 > 10000 AND Col25 > 10000 order by Col6",1)
    

    Notice how we use order by F in the first formula, while order by Col6 in the second.

    You can check your sheet to see the formulas in action.