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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
edithb40
Frequent Visitor

Check if value is in another table - DAX

I have two tables with a one-to-many relationship on the child's id. The table has other columns including the columns I have depicted below.  The two tables are:

Child table
child_idlocation
1Nigeria
2Ghana
3South Africa
4Kenya
5Zambia
6 
parents table
parents_idchild_idparentlocation
1001fatherNigeria
1011motherTogo
1032fatherKenya
1042motherKenya
1053fatherNigeria
1063motherSouth Africa
1074fatherNigeria 
1084motherNigeria
1095father 
1095mother 

 

I want to add a new column to the the child's table that returns YES if the child has the same location as either parents, NO if the location of the child is not the same as that of (either) the parents, BLANK if the child's location is blank. i.e I want to add the new column like the one below. How can I do this using DAX? Any help would be appreciated. Thank you so much. 

Child's table with added column
child_idlocationnew column
1Nigeriayes
2Ghanano
3South Africayes
4Kenyano
5Zambiano
6  
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try creating a new column like

new column =
IF (
    NOT ISBLANK ( 'child table'[location] ),
    IF (
        'child table'[location]
            IN SELECTCOLUMNS ( RELATEDTABLE ( 'parent table' ), 'parent table'[location] ),
        "Yes",
        "No"
    )
)

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Try creating a new column like

new column =
IF (
    NOT ISBLANK ( 'child table'[location] ),
    IF (
        'child table'[location]
            IN SELECTCOLUMNS ( RELATEDTABLE ( 'parent table' ), 'parent table'[location] ),
        "Yes",
        "No"
    )
)

Thank you so much. Before I posted my question, I have used the following dax query to create a new column. And it seem to be providing the same answer as your suggested solution. Just for learning purposes, am I correct?

DAX:

New column = IF(CONTAINS(RELATEDTABLE(parent_table), parent_table[location], child_table[location]),"yes", "no")

 

That's almost correct, the only slight issue is that you are not testing to see if the child location is blank. Other than that your solution is basically the same as mine, I think that IN is just another way of writing using CONTAINS that is just a little more readable.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.