为BI提供Power BI多个条件

时间:2020-10-05 15:17:28

标签: powerbi dax countif

我正在尝试实现以下组合项和代码的优势。

A和B列具有项目和代码,C列为我的状态。

1。如果同一项目在代码后带有“ YP”,而在代码后没有“ YP”,那么我的状态是“ NotOKay”。

示例;

enter image description here

2。同一项目的代码后没有“ YP”,则我的状态为“好”。

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以尝试以下适用于 measure column -

的以下代码
ok_not_ok = 

VAR item_count = 
CALCULATE(
    COUNT(your_table_2[item]),
    ALLEXCEPT(your_table_2,your_table_2[item])
)

VAR item_count_with_yp =
CALCULATE(
    COUNT(your_table_2[item]),
    FILTER(
        ALLEXCEPT(your_table_2,your_table_2[item]),
        RIGHT(your_table_2[code],3) = "-YP"            
    )
) + 0

RETURN IF(
    item_count_with_yp = 0 || item_count=item_count_with_yp, 
    "OK", 
    "NOT OK"
)

这是示例输出-

enter image description here