简体   繁体   English

Power BI-测量以计算不重复计数

[英]Power BI - Measure to calculate the distinct count

I have a requirement where I am calculating the distinct count while leaving a particular value. 我有一个要求,我要在计算不重复计数的同时保留特定值。

For example, 例如,

Consider this - 考虑一下-

BU    Rev     RevDes   concatenatedcolumnfordistinctcount
1A     AppR      1A           1AAppR1A
1A     AppR      2A           1AAppR2A
1A     FAppR     3A           1AFAppR3A
2A     BcR       1A           2ABcR1A
2A     BcR       1A           2ABcR1A
2A     AcR       1A           2AAcR1A

For hierarchy, Imagine something like this - 对于层次结构,想象一下这样的事情-

  1. BU - Grand Parent BU-祖父母

  2. RevDes - Parent RevDes-父级

  3. Rev - Child Rev-儿童

First Step – Calculate the distinct count of the concatenated output column 第一步–计算串联输出列的不重复计数

For Business Unit, 1A – it will be 3 对于业务部门,1A –将为3

For Business Unit 2A – it will be 2 对于业务部门2A –将是2

Second Step - check whether Rev Des – FAppR is present for a business unit. 第二步-检查某个业务部门是否存在Rev Des – FAppR。

FAppR is present for Business Unit 1A - so it becomes 1. FAppR存在于业务部门1A-因此变为1。

FAppR is not present for Business Unit 2A - so it stays the same - 2. FAppR不存在于业务部门2A-因此保持不变-2。

Final output :- 最终输出:-

So the final output when both business units 1A and 2A are selected is 1 + 2 = 3. 因此,当同时选择业务部门1A和2A时,最终输出为1 + 2 = 3。

The total output expected is 3 预期总产量为3

You don't need the concatenated column. 您不需要串联的列。 You can do this with two measures: 您可以通过两种措施来做到这一点:

UniqueCount = 
IF ( 
    COUNTROWS ( 
        FILTER ( 
            Table1, 
            Table1[Rev] = "FAppR"
        )
    ) > 0,
    1,
    COUNTROWS ( 
        GROUPBY ( 
            Table1,
            Table1[BU],
            Table1[Rev],
            Table1[RevDes]
        )
    )
)

and

UniqueSum = 
SUMX ( 
    DISTINCT ( Table1[BU] ),
    [UniqueCount]
)

Use the UniqueSum measure for your required output. UniqueSum度量用于所需的输出。

Worked example PBIX file: https://pwrbi.com/so_54693457/ 工作的示例PBIX文件: https ://pwrbi.com/so_54693457/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM