Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Unable to Use RELATED in a measure


This is a peculiar issue I'm facing -

Lets say I've a following Table A -

UniqueID User
A1 Adam
A2 Dim
A3 Jo
A4 Bill

and Table B -

UniqueID RelatedID Type
B1 A2 Email
B2 Email
B3 A3 Note
B4 C5 App

They have an Active Relationship- (Table A[UniqueID] 1:N Table B[RelatedID]).

My Slicer is Based of - TableA[User] and I wanted a count of only those IDs to show up which had a user in Table A

I Made the Following Measure -


EmailCount = 
Var _eCount = 
CALCULATETABLE(TableB, TableB[Type] =  "Email" && TableB[RelatedID] <> BLANK() && NOT(ISBLANK(RELATED(TableA[User]))))

Return COUNTROWS(_eCount)

I'm getting the following error -

The column 'TableA[User]' either doesn't exist or doesn't have a relationship to any table available in the current context

Not sure what I'm doing wrong here.


Solution

  • EmailCount = 
    Var _eCount = 
    CALCULATETABLE(TableB, 
    FILTER(TableB, 
    
    TableB[Type] =  "Email" && TableB[RelatedID] <> BLANK() && NOT(ISBLANK(RELATED(TableA[User])))))
    
    Return COUNTROWS(_eCount)
    

    Explanation:

    Your original expands as follows. i.e. ALL() can only cover columns from the same table and there is no Table A to reference. The FILTER in my solution above permits access to the expanded table (in this case both tables)

    enter image description here