Forum Discussion
Create a table to relate two other tables
- 3 years ago
Here is one way of creating a dimension table using DAX. The source tables are:
Table 1:
Table 2:
(Note how the list of names is different between tables).
In the ribbon, under "Modeling", select new table and type in the equivalent to:
Name Table = VAR _t1 = VALUES ( 'Table 1'[Player name] ) // Creates a table of unique values for table 1 names VAR _t2 = VALUES ( 'Table 2'[Player name] ) // Creates a table of unique values for table 2 names RETURN DISTINCT ( UNION ( _t1, _t2 ) ) // UNION appends the tables contained within, creating a table of all the values listed in tables _t1 & _t2. DISTINCT in turn removes the duplicate valuesNow you need to create the relationship between this new Name Table and each corresponding field in the original tables. Select the name field in the Name Table and drag it to match the corresponding field in the other tables. Once they are created, double click on the relationship to check the nature of the relationship (you should "always" aim to create a one-to-many (or many-to-one in the GIF), single direction. Check that the fields are the correct ones. Visually you can see the direction of the relationship (single arrow) and that it is 1-to-* (one-to-many). Check that the fields are the correct ones.
Sample PBIX file attached
Here is one way of creating a dimension table using DAX. The source tables are:
Table 1:
Table 2:
(Note how the list of names is different between tables).
In the ribbon, under "Modeling", select new table and type in the equivalent to:
Name Table =
VAR _t1 =
VALUES ( 'Table 1'[Player name] ) // Creates a table of unique values for table 1 names
VAR _t2 =
VALUES ( 'Table 2'[Player name] ) // Creates a table of unique values for table 2 names
RETURN
DISTINCT ( UNION ( _t1, _t2 ) )
// UNION appends the tables contained within, creating a table of all the values listed in tables _t1 & _t2. DISTINCT in turn removes the duplicate values
Now you need to create the relationship between this new Name Table and each corresponding field in the original tables. Select the name field in the Name Table and drag it to match the corresponding field in the other tables. Once they are created, double click on the relationship to check the nature of the relationship (you should "always" aim to create a one-to-many (or many-to-one in the GIF), single direction. Check that the fields are the correct ones. Visually you can see the direction of the relationship (single arrow) and that it is 1-to-* (one-to-many). Check that the fields are the correct ones.
Sample PBIX file attached