Power Bi / Dax:汇总带有过滤器的表格

时间:2020-05-10 06:33:18

标签: powerbi dax powerbi-desktop

我有这张桌子:

IP  Technology  Status
IP1 T1  Passed
IP1 T1  Passed
IP1 T1  Failed
IP1 T2  Failed
IP1 T2  Failed
IP1 T2  Passed
IP2 T3  Passed
IP2 T3  Failed
IP3 T4  Passed
IP3 T4  Passed
IP3 T5  Passed
IP3 T5  Passed
IP3 T5  Passed
IP3 T5  Passed
IP3 T5  Passed
IP2 T6  Passed
IP2 T6  Passed
IP2 T6  Passed
IP2 T6  Passed

我必须删除一些技术(T2和T6)并显示以下摘要表: (我只对“通过”结果感兴趣,但在“失败”列中留作参考)

IP   Failed Passed  100% Passed
IP1  33%    67%     No
IP2  50%    50%     No
IP3  0%     100%    Yes

这就是我所做的: 我创建了两个临时表来计算通过的测试数和测试的总数:

Table1 =
CALCULATETABLE (
    GROUPBY (
        'Table',
        'Table'[IP],
        'Table'[Status],
        "#Passed", COUNTAX ( CURRENTGROUP (), ( 'Table'[Status] = "Passed" ) )
    ),
    'Table'[Technology] = "T1"
        || 'Table'[Technology] = "T3"
        || 'Table'[Technology] = "T4"
        || 'Table'[Technology] = "T5"
)
Test2 =
CALCULATETABLE (
    GROUPBY (
        'Table',
        'Table'[IP],
        "#scan", COUNTAX ( CURRENTGROUP (), ( 'Table'[IP] ) )
    ),
    'Table'[Technology] = "T1"
        || 'Table'[Technology] = "T3"
        || 'Table'[Technology] = "T4"
        || 'Table'[Technology] = "T5"
)

在表1中,我使用LOOKUPVALUE添加了表2中的测试总数,并计算了“%Passed”。

当我想使用IF语句获得“ 100%通过”标志(是/否)时:

100% Passed = IF(%'Table Test1'[%Passed]=1,"Yes","No")

我收到此错误消息:

The following syntax error occurred during parsing: invalid token, Line1, Offset 4, %

是因为“%Passed”是计算所得的字段吗?你知道解决方法吗?我已经为此工作了好几天,我感到很沮丧。有没有更有效的方法来获得此结果?

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我个人更喜欢SUMMARIZE胜过GROUPBY,尽管它们非常相似。您可以使用ADDCOLUMNS添加其他逻辑,这些逻辑引用您在汇总中计算出的列以获取100% Passed列。

Summary =
CALCULATETABLE (
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[IP],
            "% Passed", DIVIDE (
                CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Status] = "Passed" ),
                COUNTROWS ( 'Table' )
            )
        ),
        "100% Passed", IF ( [% Passed] = 1, "Yes", "No" )
    ),
    NOT ( 'Table'[Technology] IN { "T2", "T6" } )
)

Result