0

I'm trying to figure out how to dynamically update a section of my google query taking a value from another cell.

I'm filtering my query with a date, e.g. WHERE A Date > TODAY()-10

What I'm trying to do is have a value in a cell (P1), and have my today()-10 take the number from P1 and use that in today()-10

So if in cell P1 I put the value 20

my query would update to today()-20

I've tried using indirect, and also just referencing the cell but can't get either to work:

My latest attempt without indirect is:

=query(query('Data - Google GA'!$A:$H,"SELECT B, SUM(C), SUM(D), SUM(E), SUM(F), SUM(G), SUM(G)/SUM(E) WHERE A >= DATE '"&text(today()-"'&'"P1&"'&'","yyyy-mm-dd")& "' GROUP BY B ORDER BY SUM(E) DESC LABEL B 'Campaign', SUM(C) 'Impressions', SUM(D) 'Clicks', SUM(E) 'Cost', SUM(F) 'Sales', SUM(G) 'Revenue', SUM(G)/SUM(E) 'ROAS'",1),"SELECT * WHERE Col7 < 3.5",1)

I've created a simplified version here https://docs.google.com/spreadsheets/d/19FL5suHAnKYzeW7TVja52o-6TfAmBPhNpBcKGPOjLUw/edit#gid=0

In cell N4 I've added the formula I was trying.

thanks for any help!

1 Answer 1

0

I believe this (in your example file) will work:

=query(A:F,"select sum(B), sum(C) where A > date '"& Text(today()-P1,"yyyy-mm-dd") & "'",1)
1
  • That's great thanks, worked perfectly! I'll know in future not to try and over complicate it! I was so lost in it I wouldn't have thought of that. Thanks Commented Nov 4, 2022 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.