title: BigQuery Data Studio Custom Query
body: <p>I am trying to connect my Custom Query in BigQuery with Data Studio. I have read the guide from here: <a href="https://support.google.com/360suite/datastudio/answer/6370296?hl=en&amp;ref_topic=6370347" rel="nofollow noreferrer">https://support.google.com/360suite/datastudio/answer/6370296?hl=en&amp;ref_topic=6370347</a> but I have a few more questions.</p>
  
  <p>My query is supposed to pull last 7 days funnel flow data so when using custom query in Data Studio, how can I write in such a way that BQ will pull the data, if possible?</p>
  
  <p>If not, how can I modify my query in such a way that Data Studio will pull the data from BigQuery based on the date range I define in Data Studio? I will add the date range selector in Data Studio.</p>
  
  <p>Below is the sample of my query to get goal funnel data.</p>
  
  <pre><code>SELECT
    s0.fullVisitorId,
    s0.visitId,
    s0.firstHit,
    s1.firstHit
  FROM (
  SELECT
      fullVisitorId,
      visitId,
      MIN(hits.hitNumber) AS firstHit
      FROM
      (TABLE_DATE_RANGE([xxx.ga_sessions_],
                  DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY'),
                  CURRENT_TIMESTAMP()))
      WHERE
      REGEXP_MATCH(hits.page.pagePath, '/pageA/')
      AND totals.visits = 1
      GROUP BY
      fullVisitorId,
      visitId) s0
  LEFT OUTER JOIN EACH (
  SELECT
      fullVisitorId,
      visitId,
      MIN(hits.hitNumber) AS firstHit
      FROM
      (TABLE_DATE_RANGE([xxx.ga_sessions_],
                  DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY'),
                  CURRENT_TIMESTAMP()))
      WHERE
      REGEXP_MATCH(hits.page.pagePath, '/pageB/')
      AND totals.visits = 1
      GROUP BY
      fullVisitorId,
      visitId) s1
  ON
      s0.fullVisitorID = s1.fullVisitorID
      AND s0.visitID = s1.visitID
  </code></pre>