Power Bi/Dax: Summarize table with filters

杀马特。学长 韩版系。学妹 提交于 2021-02-11 06:24:05

问题


I have this table:

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

I have to remove some of the Technology (T2 and T6) and show the following summary table: (I am interested only in the ‘Passed’ results but left the ‘failed’ column for reference)

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

This is what I did: I created two temporary tables to calculate the number of passed tests and the total number of tests:

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"
)

In Table1, I added the total number of tests from Table2 using LOOKUPVALUE and calculated the ‘%Passed’.

When I want to get the ‘100% Passed’ flag (Yes/No) using IF statement:

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

I get this error message:

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

Is it because the ‘%Passed’ is a calculated field? Do you know a way around? I’ve been working on this for days and I’m getting frustrated. Is there a more efficient way to get this result?

Thanks in advance for your help.


回答1:


I personally prefer SUMMARIZE over GROUPBY although they are quite similar. You can use ADDCOLUMNS to add additional logic that refers to columns you calculated in your summarization to get the 100% Passed column.

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" } )
)



来源:https://stackoverflow.com/questions/61708081/power-bi-dax-summarize-table-with-filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!