Search code examples
dategoogle-sheetsgoogle-sheets-formulagoogle-sheets-querygoogle-query-language

How to create a query that only populates data with dates in the AH column that are within the last 7 days


I am trying to create a query that pulls our activation's (Column AH = activation date) for the past 7 days. How do I build this formula?

I tried guessing at the formula below but it is not working

=QUERY(DATA!1:1000, "SELECT A, B, C, D, E, F, G, H, I, J, K, L, M, N, P, AH, AJ WHERE AH > ((Today()-7) AND B <> 'Rep'",1)

The below formula works for pulling data with a date (value) in column AH but I only want to see dates within the last 7 days

=QUERY(DATA!1:1000, "SELECT A, B, C, D, E, F, G, H, I, J, K, L, M, N, P, AH, AJ WHERE AH is not null AND B <> 'Rep'",1)

Solution

  • try like this:

    =QUERY(DATA!1:1000, 
     "select A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,AH,AJ 
      where AH is not null 
      and B <> 'Rep'
      and AH <= date '"&TEXT(TODAY(),   "yyyy-mm-dd")&"'
      and AH >= date '"&TEXT(TODAY()-7, "yyyy-mm-dd")&"'", 1)