【问题标题】:How to enhance combination code with a time variable如何使用时间变量增强组合代码
【发布时间】:2020-12-11 09:05:22
【问题描述】:

我通过 v-shex-msft 找到了以下代码,我想用它来提供一个组合列表。 Kudos to him。现在我想添加一个时间变量,以便仅组合 24 小时内发生的事件。不幸的是,过滤器功能不允许我使用更多参数:

原代码:

Summary Table =

var temp= 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type]
            ),
            Sheet5[Customer] = EARLIER(Sheet5[Customer])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations]=EARLIER([combinations])
        ),
        [Customer]
    )
)

我尝试添加时间变量如下:

 Summary Table =

var temp = 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type], 
                Sheets5[time]
            ),
            Sheet5[Customer] = EARLIER(Sheet5[Customer]) 
            && Sheets5[time]+1 >= Earlier(Sheets5[time]) 
            && Sheets5[time]-1 <= Earlier(Sheets5[time])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations] = EARLIER([combinations])
        ),
        [Customer]
    )
)

对出了什么问题有任何想法吗?非常感谢您的帮助。

【问题讨论】:

  • “不幸的是,过滤器功能不允许我使用更多参数”是什么意思?你有什么错误吗?如果是,请在您的问题中显示错误消息。
  • 您好@mkRabbani 好建议,错误消息如下:无法在“sheet5”表中确定“时间”列的单个值。当度量公式引用包含许多值的列而未指定聚合(例如“min”、“max”、“count”或“sum”)以获得单个结果时,可能会发生这种情况。
  • 检查我的答案。

标签: powerbi combinations market-basket-analysis


【解决方案1】:

你能试试下面的代码吗-

 Summary Table =

var temp = 
SUMMARIZE(
    Sheet5,
    Sheet5[Customer],
    "Combinations",CONCATENATEX(
        FILTER(
            SUMMARIZE(
                Sheet5,
                [Customer],
                Sheet5[Type], 
                Sheets5[time]
            ),
            MAX(Sheet5[Customer]) = EARLIER(Sheet5[Customer]) 
            && MAX(Sheets5[time]) +1 >= Earlier(Sheets5[time]) 
            && MAX(Sheets5[time]) -1 <= Earlier(Sheets5[time])
        ),
        [Type]&","
    )
)

return
SUMMARIZE(
    temp,
    [combinations],
    "Number",COUNTAX(
        FILTER(
            temp,
            [combinations] = EARLIER([combinations])
        ),
        [Customer]
    )
)

【讨论】:

  • 非常感谢您的反馈。现在它不会抱怨 max 函数中设置的时间,但它仍然抱怨早期函数中的时间。它向我显示了相同的错误消息。我也尝试在 Early 中设置一个 max 函数,但它不起作用。你还有什么想法吗?
  • 在 Sheet5[Customer] 周围使用 MAX。检查我更新的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 2014-11-06
  • 1970-01-01
  • 2020-12-21
  • 2020-06-26
  • 2023-03-31
相关资源
最近更新 更多