Power BI - Measure to calculate the distinct count

点点圈 提交于 2019-12-12 01:13:16

问题


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

  2. RevDes - Parent

  3. Rev - Child

First Step – Calculate the distinct count of the concatenated output column

For Business Unit, 1A – it will be 3

For Business Unit 2A – it will be 2

Second Step - check whether Rev Des – FAppR is present for a business unit.

FAppR is present for Business Unit 1A - so it becomes 1.

FAppR is not present for Business Unit 2A - so it stays the same - 2.

Final output :-

So the final output when both business units 1A and 2A are selected is 1 + 2 = 3.

The total output expected is 3


回答1:


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.

Worked example PBIX file: https://pwrbi.com/so_54693457/



来源:https://stackoverflow.com/questions/54693457/power-bi-measure-to-calculate-the-distinct-count

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