Create A Relationship Between Tables in Excel - Microsoft Support3
Create A Relationship Between Tables in Excel - Microsoft Support3
Microsoft 365
SupportOffice All Microsoft
1. Make sure the workbook contains at least two tables, and that each table has a
Windows
Microsoft 365 support Surface column that can be mapped to a column in another table.
Xbox Search
Products Devices
Deals 2. Do one of the following: Format the data as a table, or Import external data as a
table in a new worksheet.
tables in Excel
Account & billing
Templates
enter a name.
4. Verify the column in one of the tables has unique data values with no duplicates.
Excel
More for Microsoft
support 365, Excel 2021, Excel 2019, Excel 2016, Excel 2013, Power BI Excel can only create the relationship if one column contains unique values.
Have you ever used VLOOKUP to bring a column from one table into another table? Now For example, to relate customer sales with time intelligence, both tables must
that Excel has a built-in Data Model, VLOOKUP is obsolete. You can create a relationship include dates in the same format (for example, 1/1/2012), and at least one table
between two tables of data, based on matching data in each table. Then you can create (time intelligence) lists each date just once within the column.
Power View sheets and build PivotTables and other reports with fields from each table, even
when the tables are from different sources. For example, if you have customer sales data, 5. Click Data > Relationships.
you might want to import and relate time intelligence data to analyze sales patterns by
year and month. If Relationships is grayed out, your workbook contains only one table.
All the tables in a workbook are listed in the PivotTable and Power View Fields lists.
1. In the Manage Relationships box, click New.
2. In the Create Relationship box, click the arrow for Table, and select a table from
the list. In a one-to-many relationship, this table should be on the many side. Using
our customer and time intelligence example, you would choose the customer sales
table first, because many sales are likely to occur on any given day.
3. For Column (Foreign), select the column that contains the data that is related to
Related Column (Primary). For example, if you had a date column in both tables,
you would choose that column now.
4. For Related Table, select a table that has at least one column of data that is related
to the table you just selected for Table.
5. For Related Column (Primary), select a column that has unique values that match
the values in the column you selected for Column.
When you import related tables from a relational database, Excel can often create those
relationships in the Data Model it’s building behind the scenes. For all other cases, you’ll 6. Click OK.
need to create relationships manually.
More about relationships between tables in Excel Example: Relating time intelligence data to airline
flight data
Notes about relationships
You can learn about both table relationships and time intelligence using free data on the
Example: Relating time intelligence data to airline flight data
Microsoft Azure Marketplace. Some of these datasets are very large, requiring a fast
“Relationships between tables may be needed” internet connection to complete the data download in a reasonable period of time.
Step 1: Determine which tables to specify in the relationship 1. Start Power Pivot in Microsoft Excel add-in and open the Power Pivot window.
Step 2: Find columns that can be used to create a path from one table to the next
2. Click Get External Data > From Data Service > From Microsoft Azure
Marketplace. The Microsoft Azure Marketplace home page opens in the Table
Import Wizard.
Notes about relationships
3. Under Price, click Free.
You’ll know whether a relationship exists when you drag fields from different tables
4. Under Category, click Science & Statistics.
onto the PivotTable Fields list. If you aren’t prompted to create a relationship, Excel
already has the relationship information it needs to relate the data.
5. Find DateStream and click Subscribe.
Creating relationships is similar to using VLOOKUPs: you need columns containing
matching data so that Excel can cross-reference rows in one table with those of 6. Enter your Microsoft account and click Sign in. A preview of the data should appear
another table. In the time intelligence example, the Customer table would need to in the window.
have date values that also exist in a time intelligence table.
7. Scroll to the bottom and click Select Query.
In a data model, table relationships can be one-to-one (each passenger has one
boarding pass) or one-to-many (each flight has many passengers), but not many-
8. Click Next.
to-many. Many-to-many relationships result in circular dependency errors, such as
“A circular dependency was detected.” This error will occur if you make a direct
9. Choose BasicCalendarUS and then click Finish to import the data. Over a fast
connection between two tables that are many-to-many, or indirect connections (a
internet connection, import should take about a minute. When finished, you should
chain of table relationships that are one-to-many within each relationship, but
see a status report of 73,414 rows transferred. Click Close.
many-to-many when viewed end to end. Read more about Relationships between
tables in a Data Model.
10. Click Get External Data > From Data Service > From Microsoft Azure
The data types in the two columns must be compatible. See Data types in Excel Marketplace to import a second dataset.
Data Models for details.
11. Under Type, click Data.
Other ways to create relationships might be more intuitive, especially if you are not
sure which columns to use. See Create a relationship in Diagram View in Power 12. Under Price, click Free.
Pivot.
14. Scroll to the bottom and click Select Query. Tips: By default, months are listed in alphabetical order. Using the Power Pivot add-in, you
can change the sort so that months appear in chronological order.
15. Click Next.
1. Make sure that the BasicCalendarUS table is open in the Power Pivot
16. Click Finish to import the data. Over a fast internet connection, this can take 15 window.
minutes to import. When finished, you should see a status report of 2,427,284 rows
transferred. Click Close. You should now have two tables in the data model. To 2. On the Home table, click Sort by Column.
relate them, we’ll need compatible columns in each table.
3. In Sort, choose MonthInCalendar
17. Notice that the DateKey in BasicCalendarUS is in the format 1/1/2012 12:00:00
AM. The On_Time_Performance table also has a datetime column, FlightDate, 4. In By, choose MonthOfYear.
whose values are specified in the same format: 1/1/2012 12:00:00 AM. The two
columns contain matching data, of the same data type, and at least one of the
columns (DateKey) contains only unique values. In the next several steps, you’ll use The PivotTable now sorts each month-year combination (October 2011, November 2011)
these columns to relate the tables. by the month number within a year (10, 11). Changing the sort order is easy because the
DateStream feed provides all of the necessary columns to make this scenario work. If
18. In the Power Pivot window, click PivotTable to create a PivotTable in a new or you’re using a different time intelligence table, your step will be different.
existing worksheet.
19. In the Field List, expand On_Time_Performance and click ArrDelayMinutes to add
it to the Values area. In the PivotTable, you should see the total amount of time “Relationships between tables may be needed”
flights were delayed, as measured in minutes.
As you add fields to a PivotTable, you’ll be informed if a table relationship is required to
make sense of the fields you selected in the PivotTable.
20. Expand BasicCalendarUS and click MonthInCalendar to add it to the Rows area.
21. Notice that the PivotTable now lists months, but the sum total of minutes is the
same for every month. Repeating, identical values indicate a relationship is needed.
22. In the Field List, in “Relationships between tables may be needed”, click Create.
25. Notice that the sum of minutes delayed now varies for each month.
Step 1: Determine which tables to specify in the relationship
26. In BasicCalendarUS and drag YearKey to the Rows area, above MonthInCalendar. If your model contains just a few tables, it might be immediately obvious which ones you
need to use. But for larger models, you could probably use some help. One approach is to
You can now slice arrival delays by year and month, or other values in the calendar. use Diagram View in the Power Pivot add-in. Diagram View provides a visual representation
of all the tables in the Data Model. Using Diagram View, you can quickly determine which Besides matching values, there are a few additional requirements for creating a
tables are separate from the rest of the model. relationship:
Data values in the lookup column must be unique. In other words, the column can’t
contain duplicates. In a Data Model, nulls and empty strings are equivalent to a
blank, which is a distinct data value. This means that you can’t have multiple nulls in
the lookup column.
Data types of both the source column and lookup column must be compatible. For
more information about data types, see Data types in Data Models.
To learn more about table relationships, see Relationships between tables in a Data Model.
Top of Page
Note: It’s possible to create ambiguous relationships that are invalid when used in a
PivotTable or Power View report. Suppose all of your tables are related in some way to other
tables in the model, but when you try to combine fields from different tables, you get the
“Relationships between tables may be needed” message. The most likely cause is that you’ve
run into a many-to-many relationship. If you follow the chain of table relationships that
connect to the tables you want to use, you will probably discover that you have two or more
one-to-many table relationships. There is no easy workaround that works for every situation,
but you might try creating calculated columns to consolidate the columns you want to use Need more help?
into one table.
Step 2: Find columns that can be used to create a path from Expand your skills
After you’ve identified which table is disconnected from the rest of the model, review its
Get new features first
columns to determine whether another column, elsewhere in the model, contains matching
JOIN MICROSOFT OFFICE INSIDERS
values.
For example, suppose you have a model that contains product sales by territory, and that
you subsequently import demographic data to find out if there is correlation between sales
and demographic trends in each territory. Because the demographic data comes from a
different data source, its tables are initially isolated from the rest of the model. To integrate
the demographic data with the rest of your model, you’ll need to find a column in one of
the demographic tables that corresponds to one you’re already using. For example if the
Was this information helpful? Yes No
demographic data is organized by region, and your sales data specifies which region the
sale occurred, you could relate the two datasets by finding a common column, such as a
State, Zip code, or Region, to provide the lookup.
What's new
Surface Pro 9
Azure for
students
Sitemap Contact Microsoft Privacy Terms of use Trademarks Safety & eco About our ads
© Microsoft 2023
https://support.microsoft.com/en-us/office/create-a-relationship-between-tables-in-excel-fe1b6be7-1d85-4add-a629-8a3848820be3 9/9