取消嵌套自定义维度会复制/夸大 BigQuery 中的交易收入

Posted

技术标签:

【中文标题】取消嵌套自定义维度会复制/夸大 BigQuery 中的交易收入【英文标题】:Unnesting the custom dimensions is duplicating/inflating transaction revenue in BigQuery 【发布时间】:2018-06-15 16:21:09 【问题描述】:

取消嵌套 hits.customdimension 和 hits.product.customdimension 会夸大交易收入

SELECT
     sum(totals.totalTransactionRevenue)/1000000 as revenue,
     (SELECT MAX(IF(index=10,value,NULL)) FROM UNNEST(product.customDimensions)) AS product_CD10,
     (SELECT MAX(IF(index=1,value,NULL)) FROM UNNEST(hits.customDimensions)) AS CD1
    FROM
      `XXXXXXXXXXXXXXX.ga_sessions_*`, 
      UNNEST(hits) AS hits, 
      UNNEST(hits.product) as product
     WHERE
      _TABLE_SUFFIX BETWEEN "20180608"
      AND "20180608"
      group by product_CD10,CD1

有没有一种方法可以让我得到一个平面表,如果我应用收入总和,它应该给出正确的结果。

【问题讨论】:

【参考方案1】:

将您的 UNNEST() 移动到顶部子查询 - 这样行就不会重复:

SELECT row
 ,  (SELECT MAX(letter) FROM UNNEST(row), UNNEST(qq)) max_letter
 ,  (SELECT MAX(n) FROM UNNEST(row), UNNEST(qq), UNNEST(qb) n) max_number
FROM (
  SELECT [
    STRUCT(1 AS p,[STRUCT('a' AS letter, [4,5,6] AS qb)] AS qq)
    , STRUCT(2,[STRUCT('b', [7,8,9])])
    , STRUCT(3,[STRUCT('c', [10,11,12])])
   ] AS row
)

尚未对此进行测试:

SELECT
 sum(totals.totalTransactionRevenue)/1000000 as revenue,
 (SELECT MAX(IF(index=10,value,NULL)) FROM UNNEST(hits) AS hit, UNNEST(hit.products) product,  UNNEST(product.customDimensions)) AS product_CD10,
 (SELECT MAX(IF(index=1,value,NULL)) FROM UNNEST(hits) AS hit, UNNEST(hit.customDimensions)) AS CD1
FROM `XXXXXXXXXXXXXXX.ga_sessions_*`, 
WHERE _TABLE_SUFFIX BETWEEN "20180608" AND "20180608"
group by product_CD10,CD1

【讨论】:

感谢您的来信。如果有效,请接受答案:)

以上是关于取消嵌套自定义维度会复制/夸大 BigQuery 中的交易收入的主要内容,如果未能解决你的问题,请参考以下文章

取消自定义维度的嵌套时,GA 网页浏览量与 BigQuery 不匹配?

GA BigQuery:使用自定义维度计算浏览量

在 Bigquery 中有效地取消嵌套值? (选择/案例/其他?)

将嵌套的自定义维度列数据转置为行 Bigquery

在 BigQuery 中按 Google Analytics 自定义维度过滤

谷歌 BigQuery 中的自定义维度