Power Pivot & DAX course · Lesson 3 of 16
Importing data into the Data Model: tables, Power Query and databases
Every way to load data into the Data Model: linked Excel tables, the PivotTable checkbox, Power Query connections and Get External Data, plus size tips.
Before you can relate tables or write a single measure, the tables have to be in the model. Excel offers several doors into the Data Model, and choosing the right one decides how easy your workbook will be to refresh next month. This lesson walks through each route with exact clicks, explains the difference between linked and imported tables, and shows how to keep the model small and fast.
Route 1: an Excel table, added directly
This is the quickest route when the data is already on a worksheet:
- Click inside the range and press Ctrl+T to make it an Excel table. Tick My table has headers.
- Rename it in Table Design › Properties › Table Name, for example
Sales. The model uses this name, and renaming later breaks fewer things if you do it now. - Choose Power Pivot › Tables › Add to Data Model. The Power Pivot window opens and the table appears as a new tab.
A table added this way is a linked table. The model keeps a link to the worksheet table: when you add rows or change values on the sheet, the model picks up the change the next time it refreshes (in the Power Pivot window: Linked Table › Update All, or simply Data › Refresh All in Excel). The tab of a linked table in Data View shows a small chain-link icon.
Route 2: the PivotTable dialog
When you insert a PivotTable from a table with Insert › PivotTable › From Table/Range, the dialog has a checkbox Add this data to the Data Model. Ticking it loads the table into the model and builds the PivotTable on top of the model rather than on a normal pivot cache. Excel also adds other tables to the model when you tick them under All in the PivotTable Fields pane. This route works even without the Power Pivot add-in, which is how many people end up with a model without realising it.
Route 3: Power Query (recommended for real data)
Power Query (Data › Get & Transform Data) imports from files, folders, databases and web pages, cleans the data with recorded steps and can load the result straight into the model. Suppose the product list arrives as a CSV file every quarter:
ProductID,Product,Category,Price,Cost
P1,Laptop,Computers,950,700
P2,Mouse,Accessories,12,5
P3,Monitor,Displays,189,120
P4,Keyboard,Accessories,35,18
P5,Tablet,Computers,420,300- Choose Data › Get Data › From File › From Text/CSV, pick
products.csvand click Transform Data to open the Power Query Editor. - Check the data types in the column headers (ABC for text, 123 for whole numbers, 1.2 for decimals). Set Price and Cost to Fixed decimal number or Decimal Number.
- Rename the query to
Productsin Query Settings › Name. - Choose Home › Close & Load › Close & Load To….
- Select Only Create Connection and tick Add this data to the Data Model, then click OK.
The table now lives only in the model, not on any worksheet, which keeps the workbook light. Next quarter you replace the CSV and click Data › Refresh All: Power Query repeats every step and reloads the model table. You can check the result with a quick PivotTable that counts products per category:
| A | B | |
|---|---|---|
| 1 | Category | Count of ProductID |
| 2 | Accessories | 2 |
| 3 | Computers | 2 |
| 4 | Displays | 1 |
| 5 | Grand Total | 5 |
PivotTable from the model: Products[Category] in Rows, ProductID in Values set to Count.
The basics of the editor are covered in Power Query basics: import, clean, append, merge, refresh and in much more depth in the separate Power Query course on this site.
Route 4: Get External Data inside Power Pivot
The Power Pivot window has its own import tools on Home › Get External Data: From Database (SQL Server, Access, Analysis Services), From Data Service, From Other Sources (a long list including Oracle, Teradata, text files and other Excel workbooks) and Existing Connections. They start the Table Import Wizard:
- Choose Home › Get External Data › From Database › From SQL Server, enter the server and database name and click Next.
- Choose Select from a list of tables and views (or write a SQL query).
- Tick the tables you need. Use Preview & Filter to untick unwanted columns and filter rows, for example only the last three years.
- Click Finish. Power Pivot imports the rows and reports how many were transferred.
This route is older than Power Query and has fewer cleaning tools, but it is still handy for straight database tables. Its settings can be revisited later with Design › Table Properties.
Data types and formats
Every column in the model has a data type: Text, Whole Number, Decimal Number, Currency, Date, or TRUE/FALSE. Click a column in Data View and look at Home › Formatting › Data Type. The type controls how the column sorts, how it relates to other tables and which DAX functions accept it. The Format drop-down next to it only controls how values are shown.
Keeping the model small
The engine compresses each column separately by storing each distinct value once and then referring to it. A column with few distinct values compresses superbly; a column where every row is different hardly compresses at all. Here is the count of distinct values for each column of our Sales table:
| A | B | C | |
|---|---|---|---|
| 1 | Column | Rows | Distinct values |
| 2 | OrderID | 10 | 10 |
| 3 | Date | 10 | 10 |
| 4 | CustomerID | 10 | 4 |
| 5 | ProductID | 10 | 5 |
| 6 | Qty | 10 | 8 |
| 7 | Amount | 10 | 10 |
Columns with high cardinality (every value different) cost the most memory.
In ten rows this does not matter, but at ten million rows the OrderID column could be larger than the rest of the model put together. Practical rules:
- Import only the columns you need. Untick unused columns in Power Query or the Table Import Wizard. You can always add one back later.
- Split date and time. A date-time column with seconds has millions of distinct values; separate Date and Time columns have at most a few thousand each.
- Round decimals to what you report. Prices with 10 decimal places compress badly.
- Prefer measures to calculated columns for anything you only aggregate (see Calculated columns vs measures in Power Pivot).
- Filter rows at the source if you only report the last few years.
Tidying up after import
- Rename tables by double-clicking the sheet tab in Data View, and columns by double-clicking the header. Short business names (Sales, Products, Amount) make DAX much easier to read.
- Hide technical columns such as keys and IDs: right-click the header › Hide from Client Tools. They stay in the model for relationships but disappear from the PivotTable field list.
- Check the size: save the workbook and compare the file size before and after a change; large jumps point to a high-cardinality column.
With tables loaded, the relationships of The Data Model and relationships: star schema and filter direction can be drawn and the measures can begin.
Check yourself
1. Which Close & Load To option loads a Power Query query only into the model?
Only Create Connection avoids a worksheet copy; the checkbox sends it to the model.
2. What is a linked table?
Power Pivot › Add to Data Model creates a table linked to the worksheet table.
3. Which column usually costs the most memory?
High cardinality columns compress poorly.
4. Where do you change a column's data type in the Power Pivot window?
Data Type and Format are in the Formatting group of the Home tab.
5. Why hide foreign key columns from client tools?
Hidden columns still work in relationships but do not clutter the field list.