【问题标题】:Use DataStudio to specify the date range for a custom query in BigQuery, where the date range influences operators in the query使用 DataStudio 为 BigQuery 中的自定义查询指定日期范围,其中日期范围会影响查询中的运算符
【发布时间】:2020-01-06 07:57:26
【问题描述】:

我目前有一个连接到 BigQuery 自定义查询的 DataStudio 信息中心。

该 BQ 查询具有硬编码的日期范围,并且其中一列 (New_or_Relicensed) 的状态可以根据该范围中指定的日期为一行动态更改。我希望能够从 DataStudio 更改该范围。

我试过了:

  • 只需将 DS 仪表板连接到 BQ 中的自定义查询,然后引入日期范围过滤器,但正如您想象的那样 - 这不起作用,因为它在已经硬编码的日期范围内运行。

  • 查看类似的答案,但他们的问题似乎并不完全相同,例如BigQuery Data Studio Custom Query

这是我在 BQ 中的查询:

SELECT t0.New_Or_Relicensed, t0.Title_Category FROM (WITH
  report_range AS
  (
    SELECT
      TIMESTAMP '2019-06-24 00:00:00' AS start_date,
      TIMESTAMP '2019-06-30 00:00:00' AS end_date
  )
SELECT
  schedules.schedule_entry_id AS Schedule_Entry_ID,
  schedules.schedule_entry_starts_at AS Put_Up,
  schedules.schedule_entry_ends_at AS Take_Down,
  schedule_entries_metadata.contract AS Schedule_Entry_Contract,
  schedules.platform_id AS Platform_ID,
  platforms.platform_name AS Platform_Name,
  titles_metadata.title_id AS Title_ID,
  titles_metadata.name AS Title_Name,
  titles_metadata.category AS Title_Category,
  IF (other_schedules.schedule_entry_id IS NULL, "new", "relicensed") AS New_Or_Relicensed
FROM
  report_range, client.schedule_entries AS schedules
JOIN client.schedule_entries_metadata 
  ON schedule_entries_metadata.schedule_entry_id = schedules.schedule_entry_id 
JOIN
  client.platforms
  ON schedules.platform_id = platforms.platform_id
JOIN
  client.titles_metadata
  ON schedules.title_id = titles_metadata.title_id
LEFT OUTER JOIN
  client.schedule_entries AS other_schedules
  ON schedules.platform_id = other_schedules.platform_id
  AND other_schedules.schedule_entry_ends_at < report_range.start_date
  AND schedules.title_id = other_schedules.title_id
WHERE
  ((schedules.schedule_entry_starts_at >= report_range.start_date AND
   schedules.schedule_entry_starts_at <= report_range.end_date) OR
  (schedules.schedule_entry_ends_at >= report_range.start_date AND
   schedules.schedule_entry_ends_at <= report_range.end_date))
) AS t0 LIMIT 100; 

基本上 - 我希望能够从谷歌数据工作室设置 start_dateend_date,并将这些日期合并到 report_range 中,然后影响其余查询中的操作(分配newrelicensed 的时间表条目。

【问题讨论】:

    标签: google-bigquery google-data-studio


    【解决方案1】:

    您是否考虑过在 Data Studio 中使用 BigQuery 连接器的自定义查询界面将 start_dateend_date 定义为 parameters 作为过滤器。

    您的查询需要重新处理... 以下示例自定义查询使用 @DS_START_DATE 和 @DS_END_DATE 参数作为表的创建日期列的过滤器的一部分。查询产生的记录将被限制在报表用户选择的日期范围内,减少返回的记录数,从而加快查询速度:

    资源:
    在数据洞察中引入 BigQuery 参数 https://www.blog.google/products/marketingplatform/analytics/introducing-bigquery-parameters-data-studio/

    运行参数化查询
    https://cloud.google.com/bigquery/docs/parameterized-queries

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      相关资源
      最近更新 更多