Power BI - 日期时间列表 - 多对多查询合并

Power BI - DateTime list - many to many query merge

假设您有 2 tables:

  1. 具有开始、结束和 ID 列(ID 不同)的数据 table。

开始、结束、ID
2020-01-01 00:01:00,2020-01-01 00:01:05,1111-1111111-1111-11-11
2020-01-01 00:01:00,2020-01-01 00:05:00,1111-1111111-1111-11-12
2020-01-01 00:02:00,2020-01-01 00:03:05,1111-1111111-1111-11-13
2020-01-01 00:10:00,2020-01-01 00:11:00,1111-1111111-1111-11-14

  1. DataTime table 使用 List.DateTimes(#datetime(2020, 01, 01, 00, 01, 0), 10, #duration(0, 0, 1, 0) 创建的列表))

2020-01-0100:01:00
2020-01-01 00:02:00
2020-01-01 00:03:00
2020-01-01 00:04:00
2020-01-01 00:05:00
2020-01-01 00:06:00
2020-01-01 00:07:00
2020-01-01 00:08:00
2020-01-01 00:09:00
2020-01-01 00:10:00

我想在 M 查询级别合并那些 table,因此如果开始大于或等于第二个 table 和结束的日期时间,则每个 ID 有 1 行小于或等于第二个 table 的 DateTime。预期结果:

日期时间,ID
2020-01-01 00:01:00,1111-1111111-1111-11-11
2020-01-01 00:01:00,1111-1111111-1111-11-12
2020-01-01 00:02:00,1111-1111111-1111-11-12
2020-01-01 00:03:00,1111-1111111-1111-11-12
2020-01-01 00:04:00,1111-1111111-1111-11-12
2020-01-01 00:05:00,1111-1111111-1111-11-12
2020-01-01 00:06:00,1111-1111111-1111-11-12
2020-01-01 00:02:00,1111-1111111-1111-11-13
2020-01-01 00:03:00,1111-1111111-1111-11-13
2020-01-01 00:06:00
2020-01-01 00:07:00
2020-01-01 00:08:00
2020-01-01 00:09:00
2020-01-01 00:10:00,1111-1111111-1111-11-14

请帮忙:)!

这个可以用M语言制作;我们需要添加 1 作为“虚拟”列

我的查询 1(日期 table)

    let
        Source = List.DateTimes(#datetime(2020, 01, 01, 00, 01, 0), 10, #duration(0, 0, 1, 0)),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Added Custom" = Table.AddColumn(#"Converted to Table", "dummy", each 1),
        #"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Column1", "Date"}}),
        #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"dummy", type text}})
    in
        #"Changed Type"

还有我的Table定义:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jY6xCQAxDANXeVzHIDmfJqsE77/GG5JShBdCxRWH1rJAwMHqA0xwAtYEHUVZce74mapl++kZm2pPKE9IT7/96cJDKA95+/Na5gc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t, ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start", type datetime}, {"End", type datetime}, {"ID", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "dummy", each Text.BeforeDelimiter([ID], "1", 1), type text),
    #"Merged Queries" = Table.NestedJoin(#"Inserted Text Before Delimiter", {"dummy"}, Query1, {"dummy"}, "Query1", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each let mydate= [Start] , mydate2 = [End] in 
Table.SelectRows([Query1],each [Date] <= mydate2 and [Date] >= mydate)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Date", "dummy"}, {"Custom.Date", "Custom.dummy"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Query1"})
in
    #"Removed Columns"

最重要的是这一行:

#"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each let mydate= [Start] , mydate2 = [End] in 
Table.SelectRows([Query1],each [Date] <= mydate2 and [Date] >= mydate))