Have you ever used VLOOKUP to bring a column from one table into another table? Now that Excel has a built-in Data Model, VLOOKUP is obsolete. You can create a relationship between two tables of data, based on matching data in each table. Then you can create 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, you might want to import and relate time intelligence data to analyze sales patterns by year and month.
All the tables in a workbook are listed in the PivotTable and Power View Fields lists.
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 need to create relationships manually.
-
Make sure the workbook contains at least two tables, and that each table has a column that can be mapped to a column in another table.
-
Do one of the following: Format the data as a table, or Import external data as a table in a new worksheet.
-
Give each table a meaningful name: In Table Tools, click Design > Table Name > enter a name.
-
Verify the column in one of the tables has unique data values with no duplicates. Excel can only create the relationship if one column contains unique values.
For example, to relate customer sales with time intelligence, both tables must include dates in the same format (for example, 1/1/2012), and at least one table (time intelligence) lists each date just once within the column.
-
Click Data > Relationships.
If Relationships is grayed out, your workbook contains only one table.
-
In the Manage Relationships box, click New.
-
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.
-
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.
-
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.
-
For Related Column (Primary), select a column that has unique values that match the values in the column you selected for Column.
-
Click OK.
More about relationships between tables in Excel
-
Notes about relationships
-
Example: Relating time intelligence data to airline flight data
-
“Relationships between tables may be needed”
-
Step 1: Determine which tables to specify in the relationship
-
Step 2: Find columns that can be used to create a path from one table to the next
-
Notes about relationships
-
You’ll know whether a relationship exists when you drag fields from different tables 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.
-
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 another table. In the time intelligence example, the Customer table would need to have date values that also exist in a time intelligence table.
-
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-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 connection between two tables that are many-to-many, or indirect connections (a chain of table relationships that are one-to-many within each relationship, but many-to-many when viewed end to end. Read more about Relationships between tables in a Data Model.
-
The data types in the two columns must be compatible. See Data types in Excel Data Models for details.
-
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 Pivot.
Example: Relating time intelligence data to airline flight data
You can learn about both table relationships and time intelligence using free data on the Microsoft Azure Marketplace. Some of these datasets are very large, requiring a fast internet connection to complete the data download in a reasonable period of time.
-
Start Power Pivot in Microsoft Excel add-in and open the Power Pivot window.
-
Click Get External Data > From Data Service > From Microsoft Azure Marketplace. The Microsoft Azure Marketplace home page opens in the Table Import Wizard.
-
Under Price, click Free.
-
Under Category, click Science & Statistics.
-
Find DateStream and click Subscribe.
-
Enter your Microsoft account and click Sign in. A preview of the data should appear in the window.
-
Scroll to the bottom and click Select Query.
-
Click Next.
-
Choose BasicCalendarUS and then click Finish to import the data. Over a fast internet connection, import should take about a minute. When finished, you should see a status report of 73,414 rows transferred. Click Close.
-
Click Get External Data > From Data Service > From Microsoft Azure Marketplace to import a second dataset.
-
Under Type, click Data.
-
Under Price, click Free.
-
Find US Air Carrier Flight Delays and click Select.
-
Scroll to the bottom and click Select Query.
-
Click Next.
-
Click Finish to import the data. Over a fast internet connection, this can take 15 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 relate them, we’ll need compatible columns in each table.
-
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, 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 these columns to relate the tables.
-
In the Power Pivot window, click PivotTable to create a PivotTable in a new or existing worksheet.
-
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 flights were delayed, as measured in minutes.
-
Expand BasicCalendarUS and click MonthInCalendar to add it to the Rows area.
-
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.
-
In the Field List, in “Relationships between tables may be needed”, click Create.
-
In Related Table, select On_Time_Performance and in Related Column (Primary) choose FlightDate.
-
In Table, select BasicCalendarUS and in Column (Foreign) choose DateKey. Click OK to create the relationship.
-
Notice that the sum of minutes delayed now varies for each month.
-
In BasicCalendarUS and drag YearKey to the Rows area, above MonthInCalendar.
You can now slice arrival delays by year and month, or other values in the calendar.
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.
-
Make sure that the BasicCalendarUS table is open in the Power Pivot window.
-
On the Home table, click Sort by Column.
-
In Sort, choose MonthInCalendar
-
In By, choose MonthOfYear.
The PivotTable now sorts each month-year combination (October 2011, November 2011) 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 you’re using a different time intelligence table, your step will be different.
“Relationships between tables may be needed”
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.
Although Excel can tell you when a relationship is needed, it can’t tell you which tables and columns to use, or whether a table relationship is even possible. Try following these steps to get the answers you need.
Step 1: Determine which tables to specify in the relationship
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 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 tables are separate from the rest of the model.
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 into one table.
Step 2: Find columns that can be used to create a path from one table to the next
After you’ve identified which table is disconnected from the rest of the model, review its columns to determine whether another column, elsewhere in the model, contains matching 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 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.
Besides matching values, there are a few additional requirements for creating a 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
Excel is not a database for sure; however, people tend to use it as a database. Since primary versions of Excel, people keep on using it for making the connection between different tables with the help of VLOOKUP, INDEX, MATCH, SUMIF, etc.
Making reports was never an easier task as handling larger datasets is a tricky thing. Excel Data Model is a true blessing that lets you save time using automatic data reports. Here we will talk about how to create a relationship in Excel. Using the Data Model, you can make the connection between two tables and a figure of the relationship in a pivot table side by side.
To understand how to create a relationship between two tables in Excel, let’s start with a quick overview of the relationship.
What is a Relationship?
Merging two different tables result in a relationship:
- Within two tables, you must find a mutual column. However, you don’t need to allocate the same name to the columns.
- The new column must have distinctive entries only.
Hundreds of tables exist in relational databases that make such kinds of relationships. In Excel, you can make a fundamental relational structure using the Data Model option. Suppose an Order data table and a Sales data table, both contain a mutual column State. And both tables have duplicate data in these columns, so you are not allowed to add that column to the new table. You have to skip the State column.
Why Is It Important to Make a Relationship?
Realizing the importance of anything helps you understand why you should use it. Just a single data table is not enough to provide all the information needed to make a report. It often happens in many cases, that’s why the need of creating relationship tables in Excel comes up.
Taking the above example, making a report about a person who marked the order is not likely to be placed in the Sales data table. Making a relationship between two tables Order and Sales just need the Order ID to extract the name from the table to be used in the Sales report.
Note: Remember that PivotTables replace the term “column” with “field.”
The Fundamental Needs
Before understanding how to create a relationship in Excel, let’s understand the basics of this process. For this, you must have Power Pivot and Power Query to complete the process of making an Excel Data Model.
Below you will find out the starting procedure:
How to Get Power Pivot
For Excel 2010, the Power Pivot add-in is needed to be downloaded from Microsoft. Once the downloading is complete, make sure to install it properly on your system.
For Excel 2013, you don’t need to download or install anything manually as the Office Pro Plus edition of Excel 2013 has a built-in Power Pivot. You just need to activate it before using it.
To activate the Power Pivot follow the steps given below:
- Open the Excel workbook and click the Ribbon on the File.
- Click on the Options and you will see a window of Excel Options.
- Next, click on Add-ins.
- On the Manage box, click the drop-down menu and choose COM Add-ins.
- Press Go and choose the checkbox for Microsoft Power Pivot for Excel.
How to Get Power Query (Get & Transform)
- For Excel 2010, similar to the Power Pivot add-in, you need to download the Power Query add-in from Microsoft.
- Once the downloading is complete, you need to install it properly and you will start seeing the Power Query on the Ribbon.
- For Excel 2013, again you don’t need to download and install anything as there is a built-in Power Query. You just have to activate it by following the same steps you did to make Power Pivot functional in Excel 2013.
- For Excel 2016 and Later, you have to go to the Data tab on Excel Ribbon to get the Power Query (Get & Transform).
How to Create a Relationship in Excel – Step-by-Step Guide
- At first, you need to set your data as tables. In the process of making a table, you have to select a random cell in the range and press Ctrl + T. From the design tab, you have to spell out a name for the table.
- Next, you have to open the data ribbon & click on the relationships button.
- To make a new relationship, you have to click on the New.
- Choose Source table & column name. To mark the table and column name, you need to record it. It does not matter what order you are using for making this relationship table. You should never underestimate the power of Excel no matter what.
- Now, you can add more relationships as required.
Things to Consider About Relationship
Keep in mind that VLOOKUPS and making relationships both are alike somehow. Duplicate data columns are needed for Excel to cross-reference rows of one table to the other.
While using relationships, you must keep in mind that there must be similar data types in both columns. For instance, connecting columns of both tables must have the same data type.
Excel 2013 holds up one to one or one to many relationships only. It simply shows that one of the tables is free from duplicate values on the linking columns. For instance, the products table must not contain similar product IDs.
Slicing these Pivot Tables is easier just the way you can do with normal Pivot Tables. For instance, you can further slice the products report on the products prices.
Do You Like Using Relationships?
Well, the relationships feature has replaced many tools and things. People skipped VLOOKUP for most of their analysis. Now, relationships features have become the central part of Excel, which is being used more and more.
You should try using relationship tables and data models in Excel. Elaborate your thoughts about using relationship tables and data models with us. I hope that you got an idea about how to create a relationship in Excel. Now, try it, share it and practice it.
Have you ever been in a VLOOKUP hell?
Its what happens when you have to write a lot of vlookup formulas before you can start analyzing your data. Every day, millions of analysts and managers enter VLOOKUP hell and suffer. They connect table 1 with table 2 so that all the data needed for making that pivot report is on one place. If you are one of those, then you are going to love Excel’s data model & relationships feature.
In simple words, this feature helps you connect one set of data with another set of data so that you can create combined pivot reports.
Practical Example – V(X)LOOKUP hell vs. Data Model heaven
Lets say you are looking sales data for your company. You have transaction data like below.
And you want to find out how many units you are selling by product category and customer’s gender.
Unfortunately, you only have product ID & customer ID.
With VLOOKUP Hell,
- You first fetch all the customer and product data and place them in separate ranges.
- Then write a vlookup formula to fetch product category, another to fetch customer gender.
- Then fill down the formulas for entire list of transactions.
- Now make a pivot table.
Assuming you have 30,000 transactions, you have to write 60,000 VLOOKUP formulas to create this one report!!!
With Data Model heaven,
- Create relationships between Sales, Products & Customer tables
- Create a pivot table
Creating a relationship in Excel – Step by Step tutorial
- First set up your data as tables. To create a table, select any cell in range and press CTRL+T. Specify a name for your table from design tab. Read introduction to Excel tables to understand more.
- Now, go to data ribbon & click on relationships button.
- Click New to create a new relationship.
- Select Source table & column name. Map it to target table & column name. It does not matter which order you use here. Excel is smart enough to adjust the relationship.
- Add more relationships as needed.
Using relationships in Pivot reports & analysis
- Select any table and insert a pivot table (Insert > Pivot table, more on Pivot tables).
- Make sure you check the “Add this data to data model” check box.
- In your pivot table field list, check “ALL” instead of “ACTIVE” to see all table names.
- Select fields from various tables to create a combined pivot report or pivot chart
Example: Category & Gender Sales Report
- Add category to row labels
- Add gender to column labels
- Add quantity to values
- and your report is ready!
Things to keep in mind when you using relationships
- Same data types in both columns: Columns that you are connecting in both tables should have same data type (ie both numbers or dates or text etc.)
- One to one or One to many relationships only: Excel 2013 supports only one to many or one to one relationships. That means one of the tables must have no duplicate values on the column you are linking to. (for example products table should not have duplicate product IDs).
- You can add slicers too: You can slice these pivot tables on any field you want (just like normal pivot tables). For example, you can further slice the above report on customer’s profession or product’s SKU size.
Benefits of Data Model based Pivot Tables
Once you have a data model in spreadsheet, you will enjoy several benefits (apart from multi-table pivots that is). They are,
- Distinct counts: This simple but often tricky to calculate number is easy to get once you have data model based pivot. Just go to value field settings and change the summary type to “Distinct count”. Here is a tip explaining how to get distinct counts in Excel pivots.
- Measures & DAX: Once you have a Data Model, you can unleash the full Power Pivot features on your workbook. You can create measures (using DAX language) and calculate things that are otherwise impossible with regular Excel. Here is an example of percentage of something calculation with DAX & Data Model, to get started.
- Pivots from data in other files & databases: You can combine data model with the abilities of Power Query to create pivots from data in other places. For example, you can make a pivot from sales data in SAP with customer data in CRM system. Here is an overview of what is Power Query?
- Pivots from more than 1mn rows of data: You can connect to very large datasets and make pivots from them with the help of data model. Here is a demo of how to set up data model for 1+mn rows of data.
- Convert Pivot Tables to formulas: Once you have a data model based pivot table, you can turn it in to a set of formulas. You can access this feature from “Analyze” ribbon. This will replace your pivot with a bunch of CUBE formulas. Here is an overview of CUBE formulas.
Drawbacks of Data Model:
Of course, its not all cup cakes and coffee with Data Model. There are a few drawbacks of data model based pivot tables.
- Compatibility: Data model & relationship feature is available only in Excel 2013 or above. This means, you cannot create or share such pivot reports with people using older versions of Excel.
- Not able to group data: In regular Pivot Tables, you can group numeric, data or text fields. But with data model pivot tables, you can no longer group data. You must create another table with the group mapping and use it as a relationship.
Download Example File
Click here to download Excel data model demo file. It contains 3 different tables and a combined pivot report (with slicer) to show you what is possible.
Do you use relationships?
Ever since discovering PowerPivot, I kind of stopped using VLOOKUP (or XLOOKUP) for most of my own analysis. Now that relationships are part of main Excel functionality, I am using them even more.
What about you? Are you using relationships & data model in Excel? What cool things are you doing with it? Share your tips with us using comments.
Want even more? Try PowerPivot
If you want even more out of your reports, then try PowerPivot. It is a new feature in Excel 2013 (available as add-in in Excel 2010) that can let you do lots of powerful analysis on massive amounts of data. Here is an introduction to PowerPivot.
Share this tip with your colleagues
Get FREE Excel + Power BI Tips
Simple, fun and useful emails, once per week.
Learn & be awesome.
-
41 Comments -
Ask a question or say something… -
Tagged under
data model, downloads, excel 2013, Learn Excel, pivot tables, relationship, vlookup
-
Category:
Excel Howtos, Pivot Tables & Charts
Welcome to Chandoo.org
Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.
Read my story • FREE Excel tips book
Excel School made me great at work.
5/5
From simple to complex, there is a formula for every occasion. Check out the list now.
Calendars, invoices, trackers and much more. All free, fun and fantastic.
Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It’s all here.
Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.
Related Tips
41 Responses to “How to use Excel Data Model & Relationships”
-
Ashish Youngy says:
Data is Excel 2013 behaves so much like a OLAP cube when using with PivotTables. And this is actually wow. Consider learning not just DAX but MDX too 🙂 Happy Excel
@Chandoo.. Have a nice and safe time in US. Best Wishes. And when they are publishing your interview in Entrepreneur 🙂
-
Buzz says:
I have been using PowerPivot in Excel 2010. My understanding was (via PowerPivot Pro blog) that Power Pivot would NOT be available in Excel 2013 in all versions; my recollection is that it was only going to be available in certain enterprise subscription editions. Thus, for individual users, it will no longer be available? For that reason I have moved some of my projects to Tableau, and do not expect to upgrade to Excel 2013.
Can you confirm the availability of Power Pivot for all Excel 2013 users , or will it be restricted and unavailable for some users?-
-
This is something that Excel is doing very poorly: letting people know what’s available with what. It also doesn’t help that they have so many packages and versions.
Excel Professional Plus has Power Pivot and Power View. I went through this last week. Spent 4 days upgrading from 365 Home Premium ($99 for the 1-yr subscription) to an additional $7/month for Professional Plus.
Also, one page on Microsoft’s site says that their Sharepoint Online Package 2 has Power View. NO! It’s not true. Sharepoint Online Package 2 will INTERACT with a spreadsheet that has PP or PV, Package 1 will not.
-
-
-
Just this weekend I upgraded from Home Premium to Professional Plus and spent time with Power View and PowerPivot.
Up to that point I never saw myself in VLOOKUP Hell, and it may not be going away any time soon. I’m surprised to discover how many of my clients are still on Excel 2003. And then I have Mac users who don’t have a lot of this great stuff available to them at all.
These are great features and I’m going to dive into the Data Models. Unfortunately, I suspect, for me, the practical use may be limited to blogposts because I can’t teach Power View in my workshops or send a client a spreadsheet that has a Power View in it.
-
thundom says:
Hi OZ,
I think the Microsoft would only upgrade the excel to a certain level instead of making it so powerful that it might threat their BI product. You know these «powerful» stuff can be easily done with a entry level crystal reports version.
Glad to listen to ur opinion on it.
I spent quite some time and energy on Excel and used it a lot, but now I am focusing energy on BI software like crystal reports.
-
thundom says:
We both know that based on the technology today. All the time we spend on the Macro and advanced function of Excel can be done easily with other softwares which costs only hundreds of bucks.
-
@Thondom
I don’t think Excel tries to be the solver of all problems
It is a generic tool
Which for about 95% of people will do what they want 95% of the time
There will always be specifics where specific custom software will do better than Excel
It is the commonness of Excel which means that I can send a model to you and it will work , most of the time, that is its strength, of course combined with its flexility in being able to be adapted to suit most needs-
thundom says:
Hi Hui,
You are right.But,
for the business and individual, who spend too much resource on Excel to meet their BI requirements and other processing requests.
Should they open their eyes to other ways to do it, in this age? Especially for many people try too much time to process stuff with thousands lines of macro programming.
It is just as when human being created gun fire, the martial arts would not be that effective.
Ppl need to be prodent when they choose their solution.
-
Hi guys, I just came across your conversation. I have an example of BI vs. Excel stuff. Here in Russia there is an ERP-system called «1C». It became a defacto standart for accounting, planning and BI / analytics. It is positioned as a flexible and powerful system and it really is.
But its reporting abilities aren’t user-friendly (or maybe just not me-friendly).
Many reports require programming and all those SQL things, so that is common for a company to have a couple of programmers who develop and code those reports.
So the common solution is to export data to Excel and then process it to be more suitable for further analysis or reporting.
Well, it’s obviously not a rule of thumb that special BI software can outperform Excel in day-to-day routine.
-
-
-
-
-
Tris says:
Hi Chandoo, thanks for publishing great Excel information. Pardon the ignorance as I havent used Data Model nor PowerPivot. But having seen your video clip on PowerPivot, how does Data Model differ from PowerPivot — the «process» seems familiar? Have a great day! And Excel to new heights! Regards,
-
@Tris, one main difference is that Data Model is part of Excel Home Premium. You’ve got to upgrade to ProPlus to get PowerPivot and Power View.
-
-
Nolberto says:
Excellent posting, some pride themselves for having sheets with thousands of formulas or complicated formulas, but in the end the important thing is to work as little as possible.
-
@Nolberto let’s not gloat yet. Some people are forced to have thousands of complicated formulas when they don’t have the fancy tools. I’m sad for the 2003 users who have to use SUMPRODUCT when the rest of us have SUMIFS available.
In the end, I think the important thing is clean, trustworthy data—however you arrive at it. People survived more than 300 years with slide rules and paper. No PowerPivot for the Wright Brothers.
-
-
koi says:
hi chandoo,
i added 2 column into sales, 1st column vlookup customer ID to CUST sheet to get the male or female, then 2nd column vlookup Product ID to Product sheet to get the product name, then after that i make pivot table out of sales sheet.
but then the result is really different from yours
the purposes is just try to do the vlookup vs add to data model to see if they get same result
thanks
-
Hi Koi,
We are using gender vs. category in the report. Can you try with that? I am sure the results will match.
-
-
koi says:
ups sorry, didnt see that you’re filtering using slicer..then it is good now the result are same with less effort 🙂
thanks
-
SPrasad says:
Hi Chandoo, .I am interested to know whether we can build a star schema or snow flake data models through relations in Excel? (trying to correlate with Qlikview)
-
Hi there,
You can create a Star schema for sure. Snow-flake is possible too. As long as all relationships are one to many (or one to one) anything is possible.
-
Nestavaro says:
What if customer.profession change its value after sometime?
Supposed we have monthly data for Sales. What if one customer is a doctor in Feb, then a pilot in October, for example?How to build data model for such that situation?
Thank you.
-
-
-
[…] Introduction to Excel 2013 Data Model & Relationships […]
-
Raghavendra Shanbog says:
Hello ,
I find this option similar to that of MS Access.
In MS Access as well we have relationship concept and once you create a relationship, you can start creating number of queries based on that.
But MS Access is not so user friendly and basically its database. Good that we are getting those options/functions in Excel.
Thanks for sharing this info.Regards,
Raghavendra Shanbog -
What is star schema and snow flake.??? Can we have next article on that if it is useful for us???
-
Roberto says:
Hi there, can anyone help? I tried testing this out in Excel using two tables. When I go to the Data tab the Relationships button does not appear at all. I am using Microsoft version 14.0.4760.1000, Microsoft Office Professional Plus 2010. Does this version have this capability? Or is there an add-in required?
-
[…] even a layperson can perform if they have the almighty Excel 2010 and PowerPivot installed. Or Excel 2013′s Data Model, which lets you mash up data from Excel Tables and serve them up directly as PivotTables with not a […]
-
Chandeep Chhabra says:
Chandoo/Hui,
The dates grouping feature does not seem to work in Data Model. Is that true or am I making a mistake somewhere?
-
Jay says:
I don’t think this is really for «lookups»…
Try creating a pivot with sale ID and customer name in row fields. It will give you ALL customer names per sale ID.
You’d need to use RELATED function in a new column in powerpivot if you want something equivalent to «vlookup»
-
Aslam says:
Please explain the difference between data model and power pivot, the functions of both of them are different and similar
thanks -
[…] Handling large volumes of data in Excel—Since Excel 2013, the “Data Model” feature in Excel has provided support for larger volumes of data than the 1M row limit per worksheet. Data Model also embraces the Tables, Columns, Relationships representation as first-class objects, as well as delivering pre-built commonly used business scenarios like year-over-year growth or working with organizational hierarchies. For several customers, the headroom Data Model is sufficient for dealing with their own large data volumes. In addition to the product documentation, several of our MVPs have provided great content on Power Pivot and the Data Model. Here are a couple of articles from Rob Collie and Chandoo. […]
-
Bernadette Savage says:
I need to use a slicer to allow a user to select vendor by name. In the background, I need to obtain the vendor ID to link to multiple datasets where the name may not be spelled consistently. Any advice?
-
Andrea says:
I’ve tried this in Excel 2016. It works great.
I can even create Cube Formulas on the Data model after I’ve inserted the pivot table.
Just for the fun of it, I tried to see if I could do Cube Formulas without creating the pivot table in advance. I can define Cube members, but it seems as if the measure part is playing tricks on me.I can’t get a Cube Value for Chocolates sold to Male customers.
With the Pivot created the formula looks like this (and works fine)
=CUBEVALUE(«ThisWorkbookDataModel»;»[Customer].[Gender].&[Male]»;»[Product].[Category].&[Chocolates]»;»[Measures].[Sum of Quantity]»)Does anyone know how I can solve this, or am I asking the impossible?
-
Kwabena Anaafi says:
I want to see the video on this topic
-
nestavaro says:
What if customer.profession change its value after sometime?
Supposed we have monthly data for Sales. What if one customer is a doctor in Feb, then a pilot in October, for example?How to build data model for such that situation?
Thank you.
-
In such case, you need to make relationships based on two columns. This kind of feature is not supported in Excel. You can use Power Query to merge tables based on multiple columns and return a consolidated giant table to Excel for reporting.
-
-
nestavaro says:
Is it able in MS Access?
I have never used access before. -
faisal says:
thanks chandooo your article is very helpfull for troubling peoples’ especially in office environment under boss pressure.
-
Ron says:
Here is an introduction to PowerPivot.
The link above is broken
-
Venkatesh says:
Hi. This has really taken my interest.. I have huge data tables to work with…and I use vlookup to fetch certain data. I have different data in different sheets…
Like customer sales (customer code, product code,qty, piece rate, total amount, branch code) data in one sheet
Branch details in another (branch code, branch address, state , region)
Customer Geographical Data in third sheet (region, region name)
Product details in fourth sheet (product code, product description and related)Now I use a vlookup to get branch name, state and product name respectively into my main sheet.
Now what I want is
customer code, product code,qty, piece rate, total amount, branch code) data in one sheet, branch address, state , region, region name, product description
Can’t his be done thru data model… I tried but it’s not working… Eitherway, I will gonthru thr session on e again and give a try… Any help, is appreciated. Thankyou
-
Achyutanand Khuntia says:
Dear All,
i am striving to do reverse relationship in Power pivot ,
example : —
1 — Data sheet
2. — Source datastep to stops — import first data sheet in power piovt and then source data , made relationship with both sheet , after created relationship i am able to do put related formula in source data sheet only (=releted(‘Source data'[Amount]), if i go to put formula in data sheet , parameter of Source data are not visible ,
could someone educate me how can i do , and utilize related formula in data sheet.
Leave a Reply
Download PC Repair Tool to quickly find & fix Windows errors automatically
In Microsoft Excel, you can create relationships between two tables based on the matching data within the table, even when the tables are from different sources. In older versions of Excel, people have used functions such as VLOOKUP, INDEX, and MATCH to create relationships between tables, but in newer versions of Excel, there is a Relationship command that you can use to create relationships between tables in Excel easily.
Follow the steps below to create relationships between tables in Excel.
Naming the Tables
- When creating a relationship between tables, the tables must be related.
- Now we are going to name both tables.
- Select the table you want to give a name to and click the Table Design tab.
- On the Table Design tab, type a name for the table in the Table Name box in the Properties group. Do the same for the other table.
Creating Relationships between tables
Now we will create the relationship between tables after naming the tables.
On the Data tab, click Relationships in the Data Tools group.
A Manage Relationships dialog box will open.
In the Manage Relationship dialog box, click the New button.
In the Create Relationship dialog box, click the drop-down arrow for the table and select a table from the list.
Now click the drop-down arrow for the Related Table and choose the related table from the list.
In the Column (Foreign) list box, select the column that is related in both tables, for example, Customer ID.
In the Related Column (Primary), select the column Customer ID because it is in both tables.
Then click OK.
Then click Close.
Using the Pivot table as a lookup
Open a new worksheet.
Select a cell, for example, cell A1.
Click the Insert tab, and click the Pivot Table button.
Now select the option From Data Model.
A PivotTable from Data Model dialog box will open.
Click the option Existing Worksheet, then click OK.
The PivotTable Fields pane will appear on the right.
Click the drop-down arrow of the table you want to use in the lookup. In this tutorial, we have selected the Customer ID field from the Order table.
We will check the check box for the Customer ID field and drag it to the Rows area in the pane.
Try to drag fields from both tables into the Rows Area.
If the table includes a price, cost, or total, drag it into the Values area.
The results will appear on the left.
We hope you have understood how to create relationships between tables in Excel.
Which key creates relationship between two tables?
When it comes to the Foreign key in Microsoft Excel, it helps to determine the relationship between tables. The Foreign key helps to connect multiple tables in a database or Excel spreadsheet. The Foreign key is to be a column that is in both tables.
What are table relationships?
A table relationship connects tables and matches data in both tables. Relationships use key fields, which are fields with the same name and data in both tables. In Microsoft Excel, the Foreign key is the primary key that lets users match data in both tables.
READ: How to add Bullets to Text Box in Excel.
Shantel has studied Data Operations, Records Management, and Computer Information Systems. She is quite proficient in using Office software. Her goal is to become a Database Administrator or a System Administrator.
Ever had multiple related tables and wondering how to create a report that connects them together in a single Pivot Table? We have just the thing with Data Model and Relationships!
This is our data that we will use. What we want to do is create a report that shows the First Name of the student and the Number of Classes that the student has taken.
The tricky part here is the First Name is in the Students Table, while the number of classes can be retrieved from the Classes Table. Both tables are linked by the StudentId column.
STEP 1: Select the Classes Table. Go to Insert > Pivot Table > New Worksheet
Make sure to tick Add this data to the Data Model. Click OK.
STEP 2: Select the Students Table. Go to Insert > Pivot Table > New Worksheet
Make sure to tick Add this data to the Data Model. Click OK.
STEP 3: Click All in PivotTable Fields and you should see both tables there.
STEP 4: Now we need to link them together! Go to PivotTable Tools > Analyze > Calculations > Relationships
Click New.
STEP 5: There are 2 sides of a relationship when we want to link them together.
The rule of thumb, is the primary table should have no duplicates. This is the Students table as it does not have duplicate Student Ids.
Set the following then Click OK.
Table – Classes
Column – StudentId
Related Table – Students
Related Column – StudentId
Click Close.
STEP 6: In the ROWS section put in the Students(FirstName) field. In the VALUES section put in the Classes (ClassName) field.
With just that, you can see that Excel was able to show the results in a merged fashion! You can see Daisy has 2 classes enrolled. And from the individual tables, you would not have that information readily available!
How to Use the Data Model in Excel Pivot Tables
Helpful Resource:
About The Author
Bryan
Bryan is a best-selling book author of the 101 Excel Series paperback books.
Excel isn’t a database, but that hasn’t stopped people from using it as one.
People have been doing this since early versions of Excel and creating relationships between different tables using VLOOKUP or INDEX and MATCH.
The good news is that more and more database-like functionality is being added with each version, and since Excel 2013 we’ve been able to add relationships to tables.
This example has an Orders table that contains data related to customer orders such as the Customer ID, Product Sold, and the Total.
Another table called Customers has the Name and Country for each Customer ID. But what do you do if you want to analyze the Orders data by customer Name or Country?
One solution would be to add two more columns to the Orders data and use a VLOOKUP function to bring in the customer Name and Country based on the Customer ID.
Another more elegant solution would be to use the pivot table Data Model to create a Relationship between the Orders table and the Customers table using the Customer ID field in both tables.
Create a table based on the Orders table.
Go to the Insert tab in the ribbon and select Pivot Table from the Tables section.
From the Create PivotTable menu.
- Select your Orders Table.
- Check the Add this data to the Data Model box.
- Press the Ok button.
Repeat these steps for the Customers table.
With either of your pivot tables created, you should see both tables in the PivotTable Fields window from the All view.
You can delete one of the pivot tables created since you only need one, the data will remain in the Data Model.
Build your pivot table with the Name from the Customers table in the Rows area and Total from the Orders table in the Values area.
- Drag the Name field from the Customers table to the Rows area. Expand the table to see fields by clicking the arrow next to the table name.
- Drag the Total field from the Orders table to the Values area.
- A notice will appear above the field list saying Relationships between tables may be needed. From here you can select Auto-Detect and let Excel guess the relationships between your tables or you can Create them yourself.
If you choose Auto-Detect, Excel will work to create the relationships and you can check the results by pressing the Manage Relationships button or just Close the window.
With this simple relationship, Excel is easily able to create the relationship. Small tables and consistent field names between tables will help Auto-Detect to work.
If you choose to Create the relationships yourself then the Create Relationship menu will open.
- Select the Orders table as the main Table.
- Select Customer ID as the Column (Foreign).
- Select the Customers table as the Related Table.
- Select Customer ID as the Related Column (Primary).
- Press the OK button to finish creating the relationship.
Now your resulting pivot table contains the customer Name from the Customers table along with the correct corresponding Total from the Orders table.
You can also create these relationships before trying to build the pivot table. You can do this from either the Data tab or the Analyze tab in the ribbon.
- Find the Relationships button in the Data tab under the Data Tools section.
- Find the Relationships button in the Analyze tab under the Calculations section.
This will open the Manage Relationships dialog box.
- Here you can see the existing relationships and select them to Edit, Activate, Deactivate or Delete.
- Create any new relationships using the New button.
This is an awesome way to avoid VLOOKUP or INDEX and MATCH, and minimize the columns in your tables.
About the Author
John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.
3 minute read
Have you ever been in a VLOOKUP hell?
Its what happens when you have to write a lot of vlookup formulas before you can start analyzing your data. Every day, millions of analysts and managers enter VLOOKUP hell and suffer. They connect table 1 with table 2 so that all the data needed for making that pivot report is on one place. If you are one of those, then you are going to love Excel’s data model & relationships feature.
In simple words, this feature helps you connect one set of data with another set of data so that you can create combined pivot reports.
VLOOKUP hell vs. Data Model Heaven
Lets say you are looking sales data for your company. You have transaction data like below.
And you want to find out how many units you are selling by product category and customer’s gender.
Unfortunately, you only have product ID & customer ID.
With VLOOKUP Hell
- You first fetch all the customer and product data and place them in separate ranges.
- Then write a vlookup formula to fetch product category, another to fetch customer gender.
- Then fill down the formulas for entire list of transactions.
- Now make a pivot table.
Assuming you have 30,000 transactions, you have to write 60,000 VLOOKUP formulas to create this one report.
With Data Model heaven
- Create relationships between Sales, Products & Customer tables
- Create a pivot table
Creating a relationship in the Data Model
- First set up your data as tables. To create a table, select any cell in range and press CTRL+T. Specify a name for your table from design tab.
- Now, go to data ribbon & click on relationships button.
- Click New to create a new relationship.
- Select Source table & column name. Map it to target table & column name. It does not matter which order you use here. Excel is smart enough to adjust the relationship.
- Add more relationships as needed.
Using relationships in Pivot reports & analysis
- Select any table and insert a pivot table (Insert > Pivot table).
- Make sure you check the “Add this data to data model” check box.
- In your pivot table field list, check “ALL” instead of “ACTIVE” to see all table names.
- Select fields from various tables to create a combined pivot report or pivot chart
Example: Category and Area Sales Report
- Add Category to rows labels
- Add Area to columns labels
- Add Quantity to values
- and your report is ready!
Excel Recognises a Relationship Between Tables may be Needed
In the demo file, the example pivot table is a Category and Area Sales Report, however when I added the fields to the pivot table, Excel recognised that I hadn’t yet made a relationship
Things to Keep in Mind When Using Relationships
- Same data types in both columns: Columns that you are connecting in both tables should have same data type (ie both numbers or dates or text etc.)
- One to one or One to many relationships only: Excel 2013 supports only one to many or one to one relationships. That means one of the tables must have no duplicate values on the column you are linking to. (for example products table should not have duplicate product IDs).
- You can add slicers too: You can slice these pivot tables on any field you want (just like normal pivot tables). For example, you can further slice the above report on customer’s profession or product’s SKU size.
Download Example File
Click here to download the example file: data-model-example.xlsx. It contains 3 different tables and a combined pivot report and a slicer to show you what is possible.
Excel directly doesn’t provide us ready to use a database, but we can create one using relationships between various tables. This type of relationship helps us identify the interconnections between the table and helps us whenever a large number of datasets are connected in multiple worksheets. We can look for or easily find out certain information very quickly.
Create Relational Tables in Excel
We will create two tables: one is the Master table and the other one is the detail table. The master table will have information like customer_id, product, sales channel, and cost. It will act as a primary table and rarely it will undergo a change. The detail table will have information like customer_id, name, and country. Data in the child table (detail table) changes frequently. We will create a relationship between two tables using the common column – customer_id in both fields.
Table 1: Order table: We create an order table with fields customer_id, Product, sales channel, and Cost.
Table 2: Customer table: We create a customer table with fields customer_id, Name, and country.
Create both tables in excel either in the same sheet or as a separate file.
Method 1: By Creating a Pivot Table
Step 1: Go to the insert tab at the top of the ribbon and then Select PivotTable.
Step 2: “Create pivot table” dialog box appears. Here select the orders table in the first selection. (Here we have selected the range in our datasheet). Make sure to check the “add this data to the data model” field and then click OK.
Step 3: Do the same process for the customer table. Visualize the pivot table fields and go to “All view”. Both tables will be displayed. Here we have selected from the ranges so range name (range 2, range 3 in our case) will be displayed.
Step 4: To build a pivot table, select the name from the Customers table. Place it in the Rows area. We can either check the mark by expanding the table or dragging the field to the rows area. Select cost from the Orders table. Place it in the Values area.
Step 5: Pivot the table fields pane showing the notice that “Relationship between the tables is needed”. There are two options available:
- We can create the relationship between tables.
- Let the excel guess by clicking on “Auto Detect”.
Step 6: In Auto Detect, excel will create a relationship. Click on “manage relationship” to check. By clicking on “Auto Detect,” simple associations with smaller tables and consistent field names may be built automatically. Once done, click on the close button.
Step 7: The pivot table so created will have the customer name from the customer’s table and the total cost from the orders table.
If we want to create a relationship by ourselves, without letting excel do the auto-creation, click on the create button in the pivot table fields.
Step 8: It will open the edit relationship menu. Select the table containing orders as the main Table. (“range” in our case). Select Customer_id for the Column (Foreign). Select the table containing Customers as the Related Table. (“range1” in our case). Select Customer_id as the Related Column (Primary). Click ok to finish the relationship creation.
The pivot table so created will have the customer name from the customer’s table and the total cost from the orders table.
Method 2: By Creating a Relationship between Two Tables
Before creating a pivot table, we can create a relationship between two tables as shown:
Step 1: Go to the Data tab on the top of the ribbon and then to the data tools group. Click on the relationships button.
Step 2: This will open the relationships manage dialog box. All the existing relationships will be displayed with “active” status. We can perform all the options viz. edit, activate, deactivate, delete, auto-detect, etc.
Step 3: Once done, click on close. This will create a table having a similar customer_id from both tables. It will display the customer’s name from the customer’s table and the total cost from the orders table.
Advantages of Relational Tables
- Aids in working with a large amount of data.
- Recognize relations among multiple tables.
- Helps in quickly searching data.
- Retrieve specific information easily and quickly.
- View the same data set in multiple ways.
- Reduce data errors and redundancy.
Excel is a powerful tool for data analysis and subsequent automation when handling large sets of data. You could be spending significant time analyzing tons of data using VLOOKUP, INDEX-MATCH, SUMIF, etc.
Thanks to the Excel Data Model, you can save precious time through automatic data reports. Find out how easily you can assign a relationship between two tables by using the Data Model and an illustration of such a relationship in a pivot table in the following section.
The Basic Requirements
You’ll need Power Pivot and Power Query (Get & Transform) to accomplish several tasks while creating Excel Data Model. Here is how you can get these features in your Excel workbook:
How to Get Power Pivot
1. Excel 2010: You’ll need to download the Power Pivot add-in from Microsoft and then install it for your Excel program on your computer.
2. Excel 2013: Office Professional Plus edition of Excel 2013 includes Power Pivot. But, you need to activate it before first use. Here is how:
- Click on File on the Ribbon of an Excel workbook.
- Then click on Options to open Excel Options.
- Now, click on Add-ins.
- Select COM Add-ins by clicking on the drop-down menu of the Manage box.
- Click on Go and then select the checkbox for Microsoft Power Pivot for Excel.
3. Excel 2016 and Later: You’ll find the Power Pivot menu on the Ribbon.
How to Get Power Query (Get & Transform)
1. Excel 2010: You can download the Power Query add-in from Microsoft. After installation, Power Query will show up on the Ribbon.
2. Excel 2013: You need to activate Power Query by following the same steps that you just did to make Power Pivot functional in Excel 2013.
3. Excel 2016 and Later: You can find Power Query (Get & Transform) by going to the Data tab on Excel Ribbon.
Create Data Model by Importing Data to the Excel Workbook
For this tutorial, you can get pre-formatted sample data from Microsoft:
Download: Sample student data (data only) | Sample student data (complete model)
You can import a database with multiple related tables from many sources like Excel workbooks, Microsoft Access, websites, SQL Server, etc. Then you need to format the data set so that Excel can utilize it. Here are the steps that you can try:
1. In Excel 2016 and later editions, click on the Data tab and select New Query.
2. You will find several ways to import data from external or internal sources. Choose the one that suits you.
3. If using Excel 2013 edition, click on Power Query on the Ribbon and then select Get External Data to choose data for import.
4. You will see the Navigator box where you need to choose which tables you need to import. Click on the check box for Select multiple items to pick several tables for import.
5. Click on Load to complete the import process.
6. Excel will create a Data Model for you using these tables. You can see the table column headers in the PivotTable Fields listings.
You can also utilize Power Pivot functions like calculated columns, KPIs, hierarchies, calculated fields, and filtered datasets from Excel Data Model. For this purpose, you’ll need to generate Data Model from a single table. You can try these steps:
1. Format your data in a tabular model by selecting all of the cells containing data and then click Ctrl+T.
2. Now, select the entire table and then click on the Power Pivot tab on the Ribbon.
3. From the Tables section, click on Add to Data Model.
Excel will create table relationships between related data from the Data Model. For this, there should be primary and foreign key relationships within the imported tables.
Excel utilizes the relationship information from the imported table as a foundation to generate connections between the tables in a Data Model.
Build Relationships Between the Tables in the Data Model
Now that you have a Data Model in your Excel workbook, you’ll need to define relationships between the tables to create meaningful reports. You need to assign a unique field identifier or primary key to each table, like Semester ID, Class Number, Student ID, etc.
The Diagram View feature of Power Pivot will let you drag and drop those fields to build a relationship. Follow these steps to create table links in Excel Data Model:
1. On the Ribbon of the Excel workbook, click on the Power Pivot menu.
2. Now, click on Manage in the Data Model section. You’ll see the Power Pivot editor as shown below:
3. Click on the Diagram View button located in the View section of the Power Pivot Home tab. You’ll see table column headers grouped according to the table name.
4. You’ll now be able to drag and drop the unique field identifier from one table to another. Following is the relationship schematic between the four tables of the Excel Data Model:
The following describes the linkage between tables:
- Table Students | Student ID to table Grades | Student ID
- Table Semesters | Semester ID to table Grades | Semester
- Table Classes | Class Number to table Grades | Class ID
5. You can create relationships by choosing a pair of unique value columns. If there are any duplicates, you’ll see the following error:
6. You’ll notice Star (*) on one side and One (1) on the other in the Diagram View of relationships. It defines that a one-to-many relationship exists between the tables.
7. On the Power Pivot editor, click on the Design tab and then select Manage Relationships to know which fields make the connections.
Generate a PivotTable Using the Excel Data Model
You can now create a PivotTable or PivotChart to visualize your data from Excel Data Model. An Excel workbook may contain only one Data Model, but you can keep updating the tables.
Because data changes over time, you can continue to use the same model and save time when working with the same data set. You’ll notice more time savings when working on data in thousands of rows and columns. To create a PivotTable based report, follow these steps:
1. On the Power Pivot editor, click on the Home tab.
2. On the Ribbon, click on PivotTable.
3. Choose any one between New Worksheet or Existing Worksheet.
4. Select OK. Excel will add a PivotTable that will show the Field List pane on the right.
Following is a holistic view of a pivot table created by utilizing the Excel Data Model for the sample student data used in this tutorial. You can also create professional pivot tables or charts from big data using the Excel Data Model tool.
Transform Complex Data Sets Into Simple Reports Using Excel’s Data Model
Excel Data model utilizes the benefits of creating relationships between tables to produce meaningful pivot tables or charts for data reporting purposes.
You can continuously update the existing workbook and publish reports on updated data. You don’t have to edit formulas or invest time in scrolling through thousands of columns and rows each time the source data updates.
What is the Data Model in Excel?
The data model in Excel is a type of data table where two or more two tables are in a relationship with each other through a common or more data series. In the data model, tables and data from various other sheets or sources come together to form a unique table that can access the data from all the tables.
For example, a data table containing tables of customers, product items, and product sellers. We can use the Excel data model to connect this dataset and create a relationship between them.
Table of contents
- What is the Data Model in Excel?
- Explanation
- Examples
- Example #1
- Example #2
- Things to Remember
- Recommended Articles
Explanation
- It allows integrating data from multiple tables by creating relationships based on a common column.
- Data models are used transparently, providing tabular data that can be used in a Pivot Table in ExcelA Pivot Table is an Excel tool that allows you to extract data in a preferred format (dashboard/reports) from large data sets contained within a worksheet. It can summarize, sort, group, and reorganize data, as well as execute other complex calculations on it.read more and Pivot Charts in excelIn Excel, a pivot chart is a built-in feature that allows you to summarize selected rows and columns of data in a spreadsheet. It is a visual representation of a pivot table that helps in the summarization and analysis of datasets, patterns, and trends.read more. In addition, it integrates the tables, enabling extensive analysis using pivot tables, power pivot, and Power View in ExcelExcel Power View is a data visualization technology that helps you create interactive visuals like graphs, charts. It allows you to analyze data by looking at the visuals you created. As a result, it makes your excel data more meaningful and insightful for better decision making.read more.
- The data model allows loading data into Excel’s memory.
- It is saved in memory, where we cannot directly see it. Then We can instruct Excel to relate data to each other using a common column. The ‘Model’ part of the data model refers to how all tables relate.
- The data model can access all the information it needs, even in multiple tables. After the data model is created, Excel has the data available in its memory. With the data in its memory, we can access the data in many ways.
You are free to use this image on your website, templates, etc, Please provide us with an attribution linkArticle Link to be Hyperlinked
For eg:
Source: Data Model in Excel (wallstreetmojo.com)
Examples
You can download this Data Model Excel Template here – Data Model Excel Template
Example #1
We have three datasets related to the salesperson: the first contains revenue information, the second includes the salesperson’s income and the third consists of the expenses of the salesperson.
To connect these three datasets and make a relationship with them, we make a data model with the following steps:
- Convert the datasets to table objects:
We cannot create a relationship with ordinary datasets. The data model works with only Excel TablesIn excel, tables are a range with data in rows and columns, and they expand when new data is inserted in the range in any new row or column in the table. To use a table, click on the table and select the data range.read more objects. To do this:
- Step 1 – We must first click anywhere inside the dataset, click on the “Insert” tab, and click on “Table” in the “Tables” group.
- Step 2 – Check or uncheck the ‘My table has headers’ option and click “OK.”
- Step 3 – We must enter the table’s name in the “Table Name” in the “Tools” group with the new table selected.
- Step 4 – Now, we can see that the first dataset is converted to a “Table” object. On repeating these steps for the other two datasets, we know that they also get converted to “Table” objects as below:
Adding the “Table” objects to the Data Model: Via Connections or Relationships.
Via Connections
- We must select one table, click on the “Data” tab, and click on “Connections.”
- There is an icon for “Add.” Expand the dropdown of “Add” and click on “Add to the Data Model” in the resulting dialog box.
- Click on “Tables” in the resulting dialog box, select one of the tables, and click “Open.”
In doing this, it would create a workbook data model with one table, and a dialog box would appear as follows:
So if we repeat these steps for the other two tables, the data model will contain all three tables.
We can now see that all three tables appear in the “Workbook Connections.”
Via Relationships
Create the relationship: Once both the datasets are table objects, we can create a relationship between them. To do this:
- First, we should click on the “Data” tab and “Relationships.”
- As a result, we can see an empty dialog box with no current connections.
- Then, click on “New,” and another dialog box appears.
- Expand the “Table” and “Related Table” dropdowns: the “Create Relationship” dialog box appears to pick the tables and columns to use for a relationship. In the expansion of “Tables,” we must select the dataset we wish to analyze somehow, and in “Related Table,” we must choose the dataset with LOOKUP values.
- The lookup table in excelLookup tables are simply named tables that are used in combination with the VLOOKUP function to find any data in a large data set. We can select the table and name it, and then type the table’s name instead of the reference to look up the value.read more is the smaller table in the case of one to many relationships. It contains no repeated values in the common column. In expanding “Column (Foreign),” we must select the common column in the main table. In “Related Column (Primary),” we must choose the common column in the related table.
- With all these four settings selected, click on “OK.” A dialog box appears as follows on clicking on “OK.”
If we repeat these steps to relate the other two tables: the “Revenue” Table with “Expenses” table, then they also get connected in the data model as follows:
Excel now creates the relationship behind the scenes by combining data in the data model based on a common column: Salesperson ID (in this case).
Example #2
Now, in the above example, we wish to create a PivotTable that evaluates or analyzes the table objects:
- We must first click on “Insert” -> “PivotTable.”
- We need to click on the “Use an external data source” option in the resulting dialog box and click on “Choose Connection.”
- Then, we must click on “Tables” in the resulting dialog box, select the “Workbook Data Model” containing three tables, and click “Open.”
- Select the “New Worksheet” option in the location and click on “OK.”
- Consequently, the “PivotTable Fields” pane will display table objects.
Now we can make changes in the PivotTable accordingly to analyze the table objects as required. - For instance, in this case, if we wish to find the total revenue or revenue for a particular salesperson, then a PivotTable is created as follows:
It is an immense help in the case of a model/table containing a large number of observations.
So, we can see that the pivot table instantly uses the data model (picking it by choosing connection) in Excel memory to show relationships between tables.
Things to Remember
- We can analyze data from several tables at once using the data model.
- By creating relationships with the data model, we surpass the need for using VLOOKUPThe VLOOKUP excel function searches for a particular value and returns a corresponding match based on a unique identifier. A unique identifier is uniquely associated with all the records of the database. For instance, employee ID, student roll number, customer contact number, seller email address, etc., are unique identifiers.
read more, SUMIF, INDEX functionThe INDEX function in Excel helps extract the value of a cell, which is within a specified array (range) and, at the intersection of the stated row and column numbers.read more, and MATCH formulas as we do not need to get all columns within a single table. - Models are implicitly created when datasets are imported in Excel from outside sources.
- We can create table relationships automatically if we import related tables with primary and foreign key relationships.
- While creating relationships, the columns that we are connecting in tables should have the same data type.
- With the pivot tables created with the data model, we can add slicers and slice them on any field at pivot tables we want.
- The advantage of the Data Model over LOOKUP() functionsThe LOOKUP excel function searches a value in a range (single row or single column) and returns a corresponding match from the same position of another range (single row or single column). The corresponding match is a piece of information associated with the value being searched.
read more is that it requires substantially less memory. - Excel 2013 supports only one-to-one or one to many relationships, i.e., one of the tables must have no duplicate values on the column we are linking to.
Recommended Articles
This article is a guide to Data Model in Excel. We discuss creating a data model from Excel tables using connections and relationships, practical examples, and a downloadable Excel template. You may learn more about Excel from the following articles: –
- Excel Value Formula
- Excel MATCH Formula
- Share an Excel Workbook
- Consolidate Data in Excel