Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need Help - Referencing columns in a different table using Direct Query.

Hi,

 

I have two tables, a student table and a family table. 

 

The student table is as follows, where Student ID is the primary Key.

 

Student IDFamilyID
1F001
2F002
3F003
4F004
5F001

 

The Family table is as follows, where many family members may belong to the same family ID..

 

FamilyIDMemberPhone
F001Dad016-456-89876
F001Mom 
F001Uncle676-876-98543
F002Dad 
F002Mom412-562-88765
F003Dad416-542-86758
F004Dad416-592-86988

 

 

I need to find the list of pupils for whom any of the family member's phone no is missing. I'm using a direct query which makes creating Calculated columns and using calculate function difficult. 

 

I need a final output of something similar to 

 

Student IDcolumn
11
21
30
40
51

 

Can anyone help me with this?

 

Thanks in advance.

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

It is not recommended to create columns due to DQ mode. so you could create a measure or create a new table.

Method 1: create a measure.

count =
CALCULATE (
    COUNT ( family[Member] ),
    FILTER ( ALL ( family ), [FamilyID] = MAX ( 'student'[FamilyID] ) ))
    - CALCULATE ( COUNTROWS ( 'student' ), ALLEXCEPT ( student, student[FamilyID] ) )

The final output is shown below:

vyalanwumsft_0-1627869898255.png

Method 2: create a new table

Newtale =
SUMMARIZE (
    'student',
    [StudentID],
    "value",
        CALCULATE (
            COUNT ( family[Member] ),
            FILTER ( ALL ( family ), [FamilyID] = MAX ( 'student'[FamilyID] ) ))
            - CALCULATE ( COUNTROWS ( 'student' ), ALLEXCEPT ( student, student[FamilyID] ) ))

The final output is shown below:

vyalanwumsft_1-1627869987978.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

It is not recommended to create columns due to DQ mode. so you could create a measure or create a new table.

Method 1: create a measure.

count =
CALCULATE (
    COUNT ( family[Member] ),
    FILTER ( ALL ( family ), [FamilyID] = MAX ( 'student'[FamilyID] ) ))
    - CALCULATE ( COUNTROWS ( 'student' ), ALLEXCEPT ( student, student[FamilyID] ) )

The final output is shown below:

vyalanwumsft_0-1627869898255.png

Method 2: create a new table

Newtale =
SUMMARIZE (
    'student',
    [StudentID],
    "value",
        CALCULATE (
            COUNT ( family[Member] ),
            FILTER ( ALL ( family ), [FamilyID] = MAX ( 'student'[FamilyID] ) ))
            - CALCULATE ( COUNTROWS ( 'student' ), ALLEXCEPT ( student, student[FamilyID] ) ))

The final output is shown below:

vyalanwumsft_1-1627869987978.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

"I'm using a direct query which makes creating Calculated columns and using calculate function difficult" - Not any more. The Composite Model has added a lot more flexibility to this, by allowing you to create a local copy of the Direct Query data model.

 

Anyway, you can do all this in the Power BI UI directly

 

Make sure your data model is correct

lbendlin_0-1627683679015.png

Then grab the Student ID from the Student table and the Phone Number from the Family table. 

Add a filter to only include empty phone numbers

Set the student to "show items with no data"

Set the Phone number column aggregation to "Count"

 

lbendlin_1-1627683790213.png

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.