What is the Data Model in Excel?
Data model in excel is a type of data table where we two or more than two tables are in relationship with each other through a common or more data series, in data model tables and data from various other sheets or sources come together to form a unique table which can have access to the data from all the tables.
- 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 Pivot Tables and Pivot Charts. It integrates the tables, enabling extensive analysis using Pivot Tables, Power Pivot, and Power View.
- The data model allows loading data into Excel’s memory.
- It is saved in memory where we cannot directly see it. Then Excel can be instructed to relate data to each other using a common column. The ‘Model’ part of the Data Model refers to how all tables relate to each other.
- Data Model can access all the information it needs even when the information is in multiple tables. After the Data Model is created, Excel has the data available in its memory. With the data in its memory, the data can be accessed in many ways.
If we have three datasets related to the salesperson: First containing revenue information, a second containing income of salesperson, and third containing expenses of the salesperson.
To connect these three datasets and make a relationship with these, we make a Data Model with the following steps:
- Convert the datasets to Table objects:
We can’t create a relationship with ordinary datasets. The data Model works with only Excel Table objects. To do this:
- Step 1 – Click anywhere inside the dataset then, click on the ‘Insert’ tab and then click on ‘Table’ in the ‘Tables’ group.
- Step 2 – Check or uncheck the option: ‘My Table has headers’ and click OK.
- Step 3 – With the new table selected, enter the name of the Table in the ‘Table Name’ in the ‘Tools’ group.
- Step 4 – Now we can see that the first dataset is converted to ‘Table’ object. On repeating these steps for the other two datasets, we see that they also get converted to ‘Table’ objects as below:
Adding the ‘Table’ objects to the Data Model: Via Connections or Relationships.
- Select one table and click on the ‘Data’ tab and then click on ‘Connections’.
- In the resulting dialog box, there is an icon of ‘Add’. Expand the dropdown of ‘Add’ and click on ‘Add to the Data Model’.
- Click on ‘Tables’ in the resulting dialog box and then select one of the tables and click ‘Open’.
On doing this, a workbook Data model would be created with one table and a dialog box appears as follows:
So if we repeat these steps for the other two tables as well, the Data Model will now contain all three tables.
We can now see that all three tables appear in the Workbook Connections.
Create the relationship: Once both the datasets are Table objects, we can create a relationship between them. To do this:
- Click on the ‘Data’ tab and then click on ‘Relationships’.
- We will see an empty dialog box as there are no current connections.
- Click on ‘New’ and another dialog box appears.
- Expand the ‘Table’ and ‘Related Table’ dropdowns: ‘A Create relationship’ dialog box appears to pick the tables and columns to use for a relationship. In the expansion of ‘Tables’, select the dataset we wish to analyze in some way, and in ‘Related Table’, select the dataset that has lookup values.
- The lookup table is the smaller table in case of one to many relationships and it contains no repeated values in the common column. In the expansion of ‘Column (Foreign)’, select the common column in the main table, in ‘Related Column (Primary)’, select the common column in the related table.
- With all these four settings selected, click on ‘OK’. A dialog box appears as follows on clicking ‘OK’.
If we repeat these steps to relate other two tables: Revenue Table with Expenses table, then they also get related 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).
Now, let’s say in the above example we wish to create a Pivot Table that evaluates or analyzes the Table objects:
- Click on ‘Insert’-> ‘Pivot Table’.
- In the resulting dialog box, click on the option stating: ‘Use an external data source’ and then click on ‘Choose Connection’.
- Click on ‘Tables’ in the resulting dialog box and select the Workbook data Model containing three tables and click ‘Open’.
- Select the ‘New Worksheet’ option in the location and click on ‘OK’.
- The Pivot Table Fields pane will display table objects.
- Now changes in Pivot Table can be done accordingly so as 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 Pivot Table is created as follows:
This is of immense help in the case of a model/table containing a large number of observations.
So, we can see that Pivot Table instantly uses the Data Model (picking it by choosing connection) in Excel memory to show relationships between tables.
Things to Remember
- Using the Data Model, we can analyze data from several tables at once.
- By creating relationships with Data Model, we surpass the need for using VLOOKUP, SUMIF, INDEX function, and MATCH formulas as we don’t need to get all columns within a single table.
- When datasets are imported in Excel from outside sources, then models are created implicitly.
- Table relationships can be created automatically if we import related tables that have 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 too and slice the pivot tables on any field we want.
- The advantage of the Data Model over LOOKUP() functions 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.
This has been a guide to Data Model in Excel. Here we discuss how to create a data model from excel tables using Connection & Relationship along with practical examples and downloadable excel template. You may learn more about excel from the following articles –