Power BI-来自Azure Cosmos DB的桌面DateTime

时间:2019-09-05 21:32:08

标签: azure azure-cosmosdb powerbi-desktop

我正在使用通过Azure Cosmos .NET SDK填充的Azure Cosmos数据库。根据文档,DateTimes应该以ISO_8601格式(https://docs.microsoft.com/en-us/azure/cosmos-db/working-with-dates)的序列化字符串存储。当我在azure门户或azure Storage Explorer应用程序中查看记录时,情况就是这样。

enter image description here

您可以看到我的StartTime和EndTime属性以及TimeStamp的格式为“ 2019-07-15T16:24:51.392Z”

当我将数据导入Power BI Desktop时,该值显示为一些奇怪的字符串/数字。例如

00636988010188048801

我认为也许是自1970年1月1日以来的毫秒数,但事实并非如此。有谁知道如何正确地将日期时间导入Power BI或如何将该值转换为日期时间?尝试仅将数据类型设置为各种DateTime选项中的任何一个都会导致错误。

高级编辑器如下所示:

let
    Source = DocumentDB.Contents("https://myurl.documents.azure.com:443/"),
    TablesDB = Source{[id="TablesDB"]}[Collections],
    TablesDB_InstanceData = TablesDB{[db_id="TablesDB",id="InstanceData"]}[Documents],
    #"Expanded Document" = Table.ExpandRecordColumn(TablesDB_InstanceData, "Document", {"id", "RunId", "InstanceId", "StartTime", "EndTime", "MessagesProcessed", "IsCompareInstance", "_ts"}, {"id", "RunId", "InstanceId", "StartTime", "EndTime", "MessagesProcessed", "IsCompareInstance", "_ts"}),
    #"Expanded RunId" = Table.ExpandRecordColumn(#"Expanded Document", "RunId", {"$v"}, {"$v"}),
    #"Expanded InstanceId" = Table.ExpandRecordColumn(#"Expanded RunId", "InstanceId", {"$v"}, {"$v.1"}),
    #"Expanded StartTime" = Table.ExpandRecordColumn(#"Expanded InstanceId", "StartTime", {"$v"}, {"$v.2"}),
    #"Expanded EndTime" = Table.ExpandRecordColumn(#"Expanded StartTime", "EndTime", {"$v"}, {"$v.3"}),
    #"Expanded MessagesProcessed" = Table.ExpandRecordColumn(#"Expanded EndTime", "MessagesProcessed", {"$v"}, {"$v.4"}),
    #"Expanded IsCompareInstance" = Table.ExpandRecordColumn(#"Expanded MessagesProcessed", "IsCompareInstance", {"$v"}, {"$v.5"})
in
    #"Expanded IsCompareInstance"

1 个答案:

答案 0 :(得分:1)

当我将其作为问题发布到Power BI社区时,那里的某人发布了处理此问题的方法:

let

ConvertTimestamp = (ts) => #datetime(1, 1, 1, 0, 0, 0) + #duration(0, 0, 0, ts / 10000000)

in

ConvertTimestamp(635912639960000000)