Forum Discussion
Creating new column based on foreign key
Hi!
I have the following problem. I have 3 tables.
SCHOOLS TABLE
ID | Name | Address
COURSES TABLE
ID | Name | School_ID
CHILDREN TABLE
ID | Name | Course_ID
How can I add to the CHILDREN TABLE the School_ID? In other words i need to create a column which looks for the children COURSE_ID, go to the courses table and look for that id and retreive the SCHOOL_ID and add that value to the children table.
Any help would be great! Thanks in advance
Hi vpirozzi3 ,
There are two situations:
1. If no ‘Many-to-Many’ relationship among the three tables, you can use ‘Related’ to add a ‘SchoolID’ column in table ‘Children’.
SchoolID = RELATED('Courses 2'[School_ID])2. If with ‘Many-to-Many’ relationship among the three tables, you need to create another table.
Table 1 = FILTER ( CROSSJOIN ( 'Childen 1', SELECTCOLUMNS ( 'Courses 1', "CourseID", 'Courses 1'[ID], "SchoolID", 'Courses 1'[School_ID] ) ), [CourseID] = 'Childen 1'[Course_ID] )Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- IceyCommunity Support
Hi vpirozzi3 ,
There are two situations:
1. If no ‘Many-to-Many’ relationship among the three tables, you can use ‘Related’ to add a ‘SchoolID’ column in table ‘Children’.
SchoolID = RELATED('Courses 2'[School_ID])2. If with ‘Many-to-Many’ relationship among the three tables, you need to create another table.
Table 1 = FILTER ( CROSSJOIN ( 'Childen 1', SELECTCOLUMNS ( 'Courses 1', "CourseID", 'Courses 1'[ID], "SchoolID", 'Courses 1'[School_ID] ) ), [CourseID] = 'Childen 1'[Course_ID] )Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.