Forum Discussion

edithb40's avatar
edithb40
Frequent Visitor
3 years ago
Solved

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  
  • 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"
        )
    )
    

3 Replies

  • 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"
        )
    )
    
    • edithb40's avatar
      edithb40
      Frequent Visitor

      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")

       

      • johnt75's avatar
        johnt75
        Super User

        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.