【问题标题】:Fill or interpolate missing dates in a matrix in PowerBI在 PowerBI 的矩阵中填充或插入缺失的日期
【发布时间】:2020-09-28 11:34:49
【问题描述】:

我组织中的同事每天都会跟踪他们资产的可用性,这样我们的老板就可以了解他们必须使用什么以及他们每天需要撑起多少雨伞。

我的同事使用矩阵(example of the matrix),为方便起见,他们将第一行作为他们开始一周的第一个日期,第二行(未显示)是他们所在的日期。

在 PowerBI 中,它很容易转置,并留下column of dates with blanks。事实证明,填补缺失的日期很困难。

我已经能够制作一些孤立的日期列表,但我无法将它们加入到原始信息中。

Excel 可以插入这些值,但 PowerBI 只想从上面复制值。 额外的警告;我暂时无法使用 Python 或 R。

这是我将表格转置以执行我想做的填充后的另一个示例:

列 1 列 2 列 3 列 4 列 5 null 卡车 卡车 汽车 汽车 null Fred Tim Alice Beatie 2019 年 8 月 8 日开始的一周 好 坏 好 好 null 坏 坏 好 好 null 坏 好 好 坏 null 好 好 好 坏 null 好 好 坏 坏 null 好 坏 坏 好 null 坏 好 坏 好 2019 年 8 月 15 日开始的一周 坏 坏 好 坏 ……………………

我想结束的是:

列 1 列 2 列 3 列 4 列 5 null 卡车 卡车 汽车 汽车 null Fred Tim Alice Beatie 2019 年 8 月 8 日 好 坏 好 好 2019 年 8 月 9 日 坏 坏 好 好 2019 年 8 月 10 日 坏 好 好 坏 2019 年 8 月 11 日 好 好 好 坏 2019 年 8 月 12 日 好 好 坏 坏 2019 年 8 月 13 日 好 坏 坏 好 2019 年 8 月 14 日 坏 好 坏 好 2019 年 8 月 15 日 坏 坏 好 坏 ……………………

提前致谢!

【问题讨论】:

  • 只需使用原始列中最早和最晚的日期创建日期列表。
  • 从概念上讲这很简单,但在 PowerBI 中机械地实现这一点被证明是困难的。
  • 我将使用List.Dates发布一个示例

标签: excel powerbi powerbi-desktop


【解决方案1】:

您可以使用List.Dates 函数来做到这一点。

举个例子,给定数据:

以下 M 代码 会将其转换为连续日期列表:

let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type any}}),

        firstDate = DateTime.Date(#"Changed Type"[Column1]{1}),
        lastDate = DateTime.Date(List.Last(#"Changed Type"[Column1])),
        days = Number.From(lastDate - firstDate) +1,

    allDates = List.Dates(firstDate,days,#duration(1,0,0,0)),
    withText = List.Combine({{#"Changed Type"[Column1]{0}},allDates}),
    #"Converted to Table" = Table.FromList(withText, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
        
in
    #"Converted to Table"

【讨论】:

  • 感谢您的 M 代码,它似乎对我有用,但我发现我无法将它加入到我的其余数据中。我认为这与; ` withText = List.Combine({{#"Changed Type"[Column1]{0}},allDates}),` 因为一旦我将日期转置到 [Column1] 中,我就有 32 列数据
  • @Alexis 这与您提出的问题不同。我建议您发布一个新问题并提供足够的信息,以便有人可以帮助您。在制作该问题之前,可能还有助于阅读帮助页面以获取有关 How to Ask a Good QuestionHow to create a Minimal, Complete, and Verifiable example 的信息,因为我相信它会比这个更复杂。
猜你喜欢
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 2022-08-15
  • 2015-12-11
  • 1970-01-01
  • 2020-01-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多