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.

Beginner 16 min read

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:

  1. Click inside the range and press Ctrl+T to make it an Excel table. Tick My table has headers.
  2. 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.
  3. 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.

Tip. Linked tables are perfect for small, hand-maintained tables such as targets, price bands or a list of regions. For data that arrives from another system every month, use Power Query instead (route 3), so that the cleaning steps are repeated automatically.

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.

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:

DAX
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
products.csv as it arrives from the purchasing system.
  1. Choose Data › Get Data › From File › From Text/CSV, pick products.csv and click Transform Data to open the Power Query Editor.
  2. 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.
  3. Rename the query to Products in Query Settings › Name.
  4. Choose Home › Close & Load › Close & Load To….
  5. 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:

AB
1CategoryCount of ProductID
2Accessories2
3Computers2
4Displays1
5Grand Total5

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.

Note. Choosing Only Create Connection is important. If you choose Table as well as ticking Add this data to the Data Model, the data is stored twice: once on a sheet and once in the model.

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:

  1. Choose Home › Get External Data › From Database › From SQL Server, enter the server and database name and click Next.
  2. Choose Select from a list of tables and views (or write a SQL query).
  3. Tick the tables you need. Use Preview & Filter to untick unwanted columns and filter rows, for example only the last three years.
  4. 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.

Watch out. Dates imported from text files sometimes arrive as Text. They sort alphabetically, cannot relate to a date table and break time intelligence. Fix the type at the source (in Power Query) rather than in Power Pivot, so it stays fixed after every refresh.

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:

ABC
1ColumnRowsDistinct values
2OrderID1010
3Date1010
4CustomerID104
5ProductID105
6Qty108
7Amount1010

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?

2. What is a linked table?

3. Which column usually costs the most memory?

4. Where do you change a column's data type in the Power Pivot window?

5. Why hide foreign key columns from client tools?