【问题标题】:How can I create a column for cumulative count in Power BI?如何在 Power BI 中为累积计数创建列?
【发布时间】:2020-07-30 01:24:27
【问题描述】:

我正在尝试在表中创建一个新列,例如此处的最后一列:

我可以根据时间戳计算添加到购物篮的同一类别的累积产品。我尝试分组并添加索引列,但时间戳非常重要(如第 7 行和第 8 行所示),我希望重置计数,因为它们与类别 1(Cat1)中的其他产品不连续。

感谢您的帮助

【问题讨论】:

  • 您好,我认为添加索引是一个很好的解决方案。但是您需要比较上面的行,以便发现差异/从类别切换到类别。我会添加一个与if #"Added Index"{[Index] +1} [Product Category] and #"Added Index"{[Index]} [Product Category] <> null then #"Added Index"{[Index]+1} = "New Category" else "same category" 有点接近的服装栏,但是我还没有测试过。

标签: timestamp powerbi dax powerquery cumulative-frequency


【解决方案1】:

这不是一个确定的解决方案,但我希望这是一个观点:

在您的文件中,对我来说,比“添加到烘焙时间戳”列更重要的是商品购买的连续性。

因此,每次出现一个类别并替换另一个类别时,都应创建一个新的单独索引。

我在这个方向上尝试了更多,但我还没有完整的解决方案。我真的希望以下步骤仍然有用:

  AddedIndex = Table.AddIndexColumn(#"Promoted Headers", "Index", 0, 1),
    //This adds your index
    #"Added Custom" = Table.AddColumn(AddedIndex, "Compare", each if AddedIndex{[Index]}[Product Category] <> AddedIndex{[Index]-1}[Product Category] then "category change" else "same category"),
     //This compares the row above in the "Product Category" column and the row below, in order to spot whenever we get a "change" in our sequence.
     // I get an error however for my the first row, because an "Index" cannot be negative. I do not know how to solve this issue yet.
    #"Added Conditional Column1" = Table.AddColumn(#"Added Custom", "Custom", each if [Compare] = "category change" then 0 else {[Index]+1})
in
    #"Added Conditional Column1"
     //In this last step I was aiming to either create a "local" index each time there is varaition between "same category" and "category change" or keep adding one but I encounter the following error: "we cannot appliy field acces to the type list"

【讨论】:

    猜你喜欢
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多