Forum Discussion
edithb40
3 years agoFrequent 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_id locatio...
- 3 years ago
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" ) )
johnt75
3 years agoSuper 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"
)
)
- edithb403 years agoFrequent 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")
- johnt753 years agoSuper 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.