【问题标题】:Excel Power Pivot - Overlapping Date RangesExcel Power Pivot - 重叠的日期范围
【发布时间】:2020-10-11 03:25:21
【问题描述】:

我有一个包含 3 列 50,000 行数据的文件 - 唯一 ID、开始日期和结束日期。

使用 Power Pivot,我需要确定具有相同唯一 ID 的任何记录是否有任何重叠日期。每个唯一 ID 出现大约 5 次。

在excel中,我会使用公式

 SUMPRODUCT: =SUMPRODUCT(($B3<=$C$3:$C$13)*($C3>=$B$3:$B$13)*($A$3:$A$13=A3))>1

虽然这个公式在 excel 中非常有效,有 50k+ 条记录,但这会破坏我的计算机。

我想知道,我将如何在 power pivot/query 中执行相同的计算。

Example of the data and calculation.

非常感谢!

【问题讨论】:

    标签: excel dax powerquery powerpivot


    【解决方案1】:

    按照 PowerQuery M 代码,这将解决您的问题。不知道50k行需要多长时间:

    let
        Quelle = Excel.CurrentWorkbook(){[Name="tab_Dates"]}[Content],
        Change_Type = Table.TransformColumnTypes(Quelle,{{"Unique ID", type text}, {"Start Date", type date}, {"End Date", type date}}),
        add_List_Dates = Table.AddColumn(Change_Type, "List_Dates", each List.Dates([Start Date], Duration.Days([End Date]-[Start Date])+1 , #duration(1,0,0,0))),
        expand_List_Dates = Table.ExpandListColumn(add_List_Dates, "List_Dates"),
        add_CountIF_ID_Date = Table.AddColumn(expand_List_Dates, "CountIF_ID_Date", (CountRows) => 
               Table.RowCount( 
                 Table.SelectRows(
                    expand_List_Dates, 
                    each 
                    ([Unique ID] = CountRows[Unique ID] and [List_Dates] = CountRows[List_Dates])))),
        Change_Type_2 = Table.TransformColumnTypes(add_CountIF_ID_Date,{{"CountIF_ID_Date", type text}}),
        ChangeValue_CountIF_ID_Date = Table.ReplaceValue(Change_Type_2, each [CountIF_ID_Date], each if [CountIF_ID_Date] <> "1" then "FALSE" else "TRUE",Replacer.ReplaceText,{"CountIF_ID_Date"}),
        Remove_Column_List_Dates = Table.RemoveColumns(ChangeValue_CountIF_ID_Date,{"List_Dates"}),
        Remove_Duplicates = Table.Distinct(Remove_Column_List_Dates)
    in
        Remove_Duplicates
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2013-02-11
      相关资源
      最近更新 更多