Search code examples
powerbimeasure

Create a measure that takes the average based on the results of count distinct from a long table?


I have a dataset in power bi that looks like this

ID1|ID2
123 456
123 456 
456 123
890 123
890 123
123 890
123 890
456 123
456 123
123 456    

The table I created shows

ID 1 Count Distinct 
123   2
456   1
890   1

I want to average based on the values of the count column. Note that ID 123 is associated with two other ID's at 456 and 890. 456 and 890 are associated with an other id just once. I want the average based on what is shown on the page at the moment.

2+1+1 which is 4/3 at 1.33

I did find this and it almost does the trick

AVERAGEX (
VALUES ( TABLE[ID1]),
CALCULATE ( COUNTROWS ( TABLE ) )
)

However what this does instead it takes the average of

ID 1 Count 
123  5 
456  3
890  3

I want the average of count distinct instead

    AVERAGEX (
VALUES ( DISTINCT(TABLE[ID1])),
CALCULATE ( DISTINCT(COUNTROWS ( TABLE )) )
)

Solution

  • I got the answer

    Average Attendees Per Day = 
    AVERAGEX (
    VALUES ( TABLE[ID1]),
    CALCULATE ( DISTINCTCOUNT(TABLE[ID2] ))
    )