01.7Split your flat table in Excel
Power Query isn’t the only way. If you are more at ease in Excel, a few formulas are enough to prepare your three tables, Customers, Products and Sales. Each one takes the form of a sheet in the workbook, which Power BI will then load. These sheets recalculate as soon as you paste a new extract over the old one, which you do again each time.
01.7.1Resources
Download these two files to repeat every step of the lesson.
01.7.2Prepare the three sheets
Open the extract file in Excel. Its data is on the first sheet, “Sheet1,” with the headers in row 1 and the sales from row 2 to row 13. The formulas below start from this sheet. If your extract has more rows or columns, or if its sheet has another name, adjust the ranges in the formulas.
Add a sheet and rename it “Customers.” Starting at A1, type the names of the columns to keep, written exactly as in the extract:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Customer ID | Name | Type | City |
In A2, type this formula:
MATCH looks for each name from A1 to D1 among the headers of “Sheet1,” in row 1, and returns its position, the third column for “Customer ID” for example. CHOOSECOLS keeps these four columns, in the order of A1 to D1. UNIQUE then removes the duplicates. 7 rows remain, one per customer.
Add a sheet and rename it “Products.” Starting at A1, type:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Product Code | Brand | Model | Category |
The formula in A2 doesn’t change. 4 rows remain, one per product.
Finally, add a sheet and rename it “Sales.” Starting at A1, type the seven columns to keep for the sales:
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Sale ID | Date | Customer ID | Product Code | Qty | Price | Amount |
In A2, the same formula does the job, over A1 to G1 and without UNIQUE, since every sale must stay:
12 rows remain, one per sale.
The columns are looked up by their name, not by their position. If the column order ever changes in the extract, the three sheets stay correct.
01.7.3Load the sheets into Power BI
First save the workbook, then close it. Power BI reads the file as it is saved, and unsaved sheets wouldn’t show up. Even once saved, a workbook left open in Excel is locked by Excel. Power Query may then refuse to read it, with a message saying the file is being used by another program. Next, in Power BI, click Get data, then Excel workbook. Check the “Customers,” “Products” and “Sales” sheets. Leave out “Sheet1,” which holds the whole extract.
In Power BI:
- Check the relationships between the tables.
- Also add your date table. Create Calendar with CALENDARAUTO.
- Mark Calendar as a date table.
01.7.4Every new extract
This route comes at a price. Power Query can connect directly to the software the extract comes from. At each refresh, it fetches the new data by itself, without any action on your part.
With the Excel sheets, you are the one who brings in each new extract. Copy its rows, without the header row, then paste them in A2 of the “Sheet1” sheet, just below the headers, over the old ones. If the new extract has fewer rows, delete the ones left below. If it has more, widen the ranges in the formulas to match. Then save the workbook, close it, and refresh Power BI.
This copy and paste calls for great care. Before you even copy, make sure the extract hasn’t been changed by mistake, a value deleted or a stray keystroke. Then copy all its rows and all its columns, and check that everything was pasted. A forgotten row or a changed value throws off every figure in the report, without any error message.
Finally, CHOOSECOLS requires Microsoft 365 or Excel 2024.
A sale keeps only the code of its customer. How does Power BI find the customer’s city from this code? That is the job of keys and relationships.
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
On the “Customers” sheet, you type in A2 the formula without UNIQUE: =CHOOSECOLS(Sheet1!A2:M13,MATCH(A1:D1,Sheet1!A1:M1,0)). How many rows does it spill?
Question 2
In the new extract, the City column comes before the Name column, in a different position from before. What happens to the three sheets?
Question 3
A new extract has 20 sales. You paste its rows in A2 of “Sheet1,” without touching the formulas, which cover Sheet1!A2:M13. What does the “Sales” sheet contain?
- Each sheet, Customers, Products and Sales, keeps its columns, looked up by name with CHOOSECOLS and MATCH. UNIQUE removes the duplicates from Customers and Products.
- Save and close the workbook before loading it into Power BI. Load the three sheets, without “Sheet1.”
- Create Calendar with CALENDARAUTO, then mark it as a date table.
- You paste each new extract yourself, with care. CHOOSECOLS requires Microsoft 365 or Excel 2024.