Search code examples
sqlgoogle-sheetsgoogle-query-language

How to combine Select, where and label functions in google sheets query


I'm trying to query a column and select cells that contain the word: pink. I want to give this new column a new name: Biz priority. Current formulas I've tried but getting errors for all of them:

  1. =QUERY(N:N,"SELECT N WHERE N CONTAINS 'pink', LABEL * 'Biz Priority'"),1

  2. =QUERY(N:N,"SELECT N LABEL N 'Biz Priority', WHERE N CONTAINS 'pink'"),1

  3. =QUERY(N:N,"SELECT N LABEL * 'Biz Priority', WHERE N CONTAINS 'pink'"),1

This works: =QUERY(N:N,"SELECT N WHERE N CONTAINS 'pink'"),1 but the column title is the same as another column which won't work for me. TIA


Solution

  • On:

    =QUERY(N:N,"SELECT N WHERE N CONTAINS 'pink', LABEL * 'Biz Priority'"),1

    Remove the comma before LABEL, change * to N, move the ) to the end.

    =QUERY(N:N,"SELECT N WHERE N CONTAINS 'pink' LABEL N 'Biz Priority' ",1)

    You can also make it case-insensistive:

    =QUERY(N:N,"SELECT N WHERE LOWER(N) CONTAINS 'pink' LABEL N 'Biz Priority' ",1)