简体   繁体   English

Analytics-> BigQuery-> Tableau | 日期返回空

[英]Analytics -> BigQuery -> Tableau | Date Returning Null

This feels like more of a Tableau issue than BigQuery or Analytics but figured I'd put it to you all. 与BigQuery或Analytics(分析)相比,这似乎更像是Tableau的问题,但我想我想给大家看。

I've created some views in BigQuery from Google Analytics for use as a live connection in Tableau but I can't for the life of me get the date field to format as a date. 我已经在BigQuery中通过Google Analytics(分析)在View中创建了一些视图,以用作Tableau中的实时连接,但是我一生都无法将date字段格式化为日期。 Even if I cast it as a date in BQ it's interpreted in Tableau as a string and if I try and change that it returns all null values. 即使我在BQ中将其强制转换为日期,它也会在Tableau中解释为字符串,并且如果尝试更改它,它将返回所有null值。

The default export in BQ is 'yyyymmdd' I can cast this as a date in the format 'yyyy-mm-dd' but still no luck. BQ中的默认导出为'yyyymmdd',我可以将其强制转换为日期,格式为'yyyy-mm-dd',但还是没有运气。

I've tried a number of different methods including running the custom SQL query from Tableau which someone in their forums recommended but nothing has worked. 我尝试了许多不同的方法,包括运行Tableau中的自定义SQL查询,该方法在其论坛中有人推荐,但没有任何效果。

Thanks for any help you can offer. 谢谢你的尽心帮助。

Cheers, 干杯,

Example: 例:

#legacySQL
SELECT
  CAST(date AS date) AS date,
  hits.hour AS hour,
  hits.eventInfo.eventAction eventAction,
  COUNT(1) eventHits
FROM (TABLE_DATE_RANGE([big-query-project-34643.162968675.ga_sessions_],
      DATE_ADD(CURRENT_TIMESTAMP(), -2, 'DAY'),
      DATE_ADD(CURRENT_TIMESTAMP(), -1, 'HOUR'))),
  (TABLE_DATE_RANGE([big-query-project-34643.162968675.ga_realtime_sessions_],
      DATE_ADD(CURRENT_TIMESTAMP(), -1, 'DAY'),
      CURRENT_TIMESTAMP()))
WHERE
  hits.eventInfo.eventCategory LIKE 'account - manage autoship'
  AND hits.type = 'EVENT'
GROUP BY
  date,
  hour,
  eventAction,
ORDER BY
  date,
  hour

Ended up figuring this out through brute force and thought I'd post the answer. 最终通过蛮力解决了这个问题,并以为我会发布答案。 Thanks to both of you for leaving comments. 感谢你们两个人发表评论。 Turns out I needed to transform the date through the concat function then cast as date. 事实证明,我需要通过concat函数转换日期,然后转换为日期。 ended up with this: 最后是这样的:

CAST(CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2)) AS DATE) AS Date,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM