快速提示: 时间 Dimension with 时间 Bands at Seconds Granularity in Power BI 和 SSAS表格

时间 Dimension with 时间 Bands at Seconds Granularity in Power BI 和 SSAS表格

过去我也写过其他有关此主题的文章,您可以找到它们 这里 这里。在第一篇文章中,我解释了如何创建“Time”时间带的维度 分钟 粒度。然后,我的一位客户要求“Time”几秒钟内的尺寸,这鼓励了我写第二篇博客文章。在第二篇博文中,虽然我没有’t做时间带,所以我在这里写第三篇文章,这是第二篇文章支持5分钟,15分钟,30分钟,45分钟和60分钟的时间带的变体。“Time”尺寸降至秒。在这篇快速文章中,我直接跳到重点,向您展示如何生成“Time”维度以三种不同的方式,即在SQL Server中使用T-SQL,使用Power Query(M)和DAX。然后是这里:

时间 Dimension at Second Grain with 功率查询 (M) Supporting 时间 Bands:

在查询编辑器中复制/粘贴以下代码’s Advanced Editor to generate 时间 dimension in 功率查询:

let
Source = Table.FromList({1..86400}, Splitter.SplitByNothing()),
    #"Renamed Columns" = Table.RenameColumns(Source,{{"Column1", "ID"}}),
    #"时间 Column Added" = Table.AddColumn(#"Renamed Columns", "时间", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0,0,0,[ID]))),
    #"Hour Added" = Table.AddColumn(#"时间 Column Added", "Hour", each 时间.Hour([Time])),
    #"Minute Added" = Table.AddColumn(#"Hour Added", "Minute", each 时间.Minute([Time])),
    #"5 Min Band Added" = Table.AddColumn(#"Minute Added", "5 Min Band", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0, 0, Number.RoundDown(Time.Minute([Time])/5) * 5, 0))  +  #duration(0, 0, 5, 0)),
    #"15 Min Band Added" = Table.AddColumn(#"5 Min Band Added", "15 Min Band", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0, 0, Number.RoundDown(Time.Minute([Time])/15) * 15, 0))  +  #duration(0, 0, 15, 0)),
    #"30 Min Band Added" = Table.AddColumn(#"15 Min Band Added", "30 Min Band", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0, 0, Number.RoundDown(Time.Minute([Time])/30) * 30, 0))  +  #duration(0, 0, 30, 0)),
    #"45 Min Band Added" = Table.AddColumn(#"30 Min Band Added", "45 Min Band", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0, 0, Number.RoundDown(Time.Minute([Time])/45) * 45, 0))  +  #duration(0, 0, 45, 0)),
    #"60 Min Band Added" = Table.AddColumn(#"45 Min Band Added", "60 Min Band", each 时间.From(#datetime(1970,1,1,0,0,0) + #duration(0, 0, Number.RoundDown(Time.Minute([Time])/60) * 60, 0))  +  #duration(0, 0, 60, 0)),
    #"Removed Other Columns" = Table.SelectColumns(#"60 Min Band Added",{"时间", "Hour", "Minute", "5 Min Band", "15 Min Band", "30 Min Band", "45 Min Band", "60 Min Band"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"时间", type time}, {"Hour", Int64.Type}, {"Minute", Int64.Type}, {"5 Min Band", type time}, {"15 Min Band", type time}, {"30 Min Band", type time}, {"45 Min Band", type time}, {"60 Min Band", type time}})
in
#"Changed Type"
继续阅读 “Quick Tips: 时间 Dimension with 时间 Bands at Seconds Granularity in Power BI 和 SSAS表格”