【问题标题】:Filtering by secondary field in DAX按 DAX 中的辅助字段过滤
【发布时间】:2020-10-20 13:03:55
【问题描述】:

我是 DAX 新手。

我的模型包含一个名为 Notices 的表。通知有 235,969 行。

通知具有字段CustomerIDNoticeNoNoticeStatus

当我将过滤上下文设置为'CANCL' Notices[NoticeStatus] 时,我可以看到有3 个通知具有CANCL 状态。

因此,下面的度量评估为 3,因为剩余的每个通知都属于 3 个单独的客户。但是,我想将聚合基于未过滤的表,但根据保留在过滤器上下文中的 CustomerID 和[ObCount] = 1 过滤掉行(聚合后)。在这种情况下,该度量需要评估为 0 或 BLANK(),因为在过滤 [ObCount] = 1 之后,过滤器上下文中的任何 CustomerID 都不会保留。

Customers with Single Notice Only = 
COUNTROWS (
    FILTER (
        SUMMARIZECOLUMNS (
            Notices[CustomerID],
            Notices,     
            "ObCount", [All Notices Outstanding]
        ),
        [ObCount] = 1
    )
)

[All Notices Outstanding] = COUNTROWS(Notices)

【问题讨论】:

    标签: powerbi dax powerbi-desktop


    【解决方案1】:

    您应该能够通过使用 CALCULATE 将过滤后的表作为表过滤器参数应用到 Notices 来做到这一点:

    Customers with Single Notice Only =
    CALCULATE (
        COUNTROWS ( Notices ),
        FILTER (
            SUMMARIZECOLUMNS (
                Notices[CustomerID],
                ALL ( Notices ),
                "ObCount", [All Notices Outstanding]
            ),
            [ObCount] = 1
        )
    )
    
    

    注意在汇总时使用ALL去掉过滤状态过滤器。

    【讨论】:

    • 那行得通。我仍在努力理解计算功能。
    猜你喜欢
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多