问题
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 -
BU - Grand Parent
RevDes - Parent
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