根据计数和存储值的组合计算百分比-Power BI

时间:2018-10-30 15:59:09

标签: filter powerbi dax measure

我有一个基本的表格,如下所示:

 DayNo. Customer    AgentsInvolved  CallID
   0      AAA              1        1858
   0      AAA              3        1859
   2      AAA              1        1860
   0      BBB              2        1862
   0      CCC              1        1863
   0      DDD              3        1864
   9      DDD              1        1865
   9      DDD              4        1866

我需要能够找到仅联系一次并且仅与1个代理进行过交谈的客户百分比。因此,在上面的示例中,在4个不同的客户中,只有客户CCC属于此类别(1个呼叫,1个AgentInvolved)

因此所需的结果将是:1/4或25%

如何创建Power BI度量来执行此计算?

3 个答案:

答案 0 :(得分:3)

尝试此措施:

Desired Result =
VAR summarizetable =
    SUMMARIZECOLUMNS (
        'table'[Customer],
        "Calls", COUNT ( 'table'[CallID] ),
        "Agents", SUM ( 'table'[AgentsInvolved] ),
        "Day", SUM ( 'table'[DayNo.] )
    )
RETURN
    COUNTROWS (
        FILTER ( summarizetable, [Calls] = 1 && [Agents] = 1 && [Day] = 0 )
    )
        / COUNTROWS ( summarizetable )

VAR summarizetable中动态创建的汇总表如下所示:

enter image description here

答案 1 :(得分:2)

这是另一种方法:

Measure = 
SUMX(
    VALUES(Table2[Customer]),
    CALCULATE(
        IF(
            DISTINCTCOUNT(Table2[CallID]) = 1 &&
              SUM(Table2[AgentsInvolved]) = 1,
            1,
            0
        ),
    Table2[DayNo.] = 0
    )
) /
DISTINCTCOUNT(Table2[Customer])

如果您还想排除分母中的0天行,则将最后一行替换为

CALCULATE(DISTINCTCOUNT(Table2[Customer]), Table2[DayNo.] = 0)

答案 2 :(得分:0)

Desired Result =
       VAR summarizetable = 
           SUMMARIZECOLUMNS (
               'table'[AgentsInvolved],
               'table'[DayNo.],
               'table'[Customer],
               "Calls", COUNT ( 'table'[CallID] )
        )
       )
    RETURN
COUNTROWS (
    FILTER ( summarizetable, [Calls] = 1 && 'table'[AgentsInvolved] = 1 && 'table'[DayNo.] = 0 )
) / DISTINCTCOUNT ( 'table'[Customer])