01.6Split your flat table in Power Query
You know why the fact table and the dimension tables should be separated. Here is how to do it in Power Query, without writing a single line of code, on the dealership sales used as the example in every lesson.
01.6.1Resources
Download these two files to repeat every step of the lesson.
01.6.2Power Query redoes the work for you
Power Query is the data preparation tool of Power BI. It also exists in Excel, on the Data tab, under “Get & Transform Data.” Every action you take there becomes a step, stored in a list. At each refresh, Power Query replays all the steps on the new data.
So you split your flat table only once. If Power Query is connected to a database, on the network or online, the split redoes itself on the new data at each refresh, on your schedule: every day, every week or every month.
The example starts from the dealership’s flat sales table, just as it comes out of an extract. It already contains two codes, the Customer ID and the Product Code, which the business software assigns to each customer and each product.
01.6.3A source query you leave untouched
To open Power Query with your data, start from Power BI Desktop. On the Home tab, click Get data, then Excel workbook, and choose your file. The Navigator window opens. Check the sheet “Sheet1,” open the arrow on the Load button, then choose Transform data. The Power Query editor opens.
To come back to it later, click Transform data, on the Home tab of Power BI Desktop.
In Power Query, each table is called a query. On import, the flat table arrives under the name “Sheet1,” the name of the sheet in the file. Rename it, for example “Flat Sales,” so you can spot it easily. Your three tables, Sales, Customers and Products, will all start from it. So keep it intact. It serves only as a starting point, and doesn’t need to go into Power BI.
The model is the set of tables Power BI keeps in memory. They are the ones you see in the Data pane, and the ones your measures use. To keep “Flat Sales” in Power Query without loading it into the model, right-click it, then clear “Enable load.” Power BI warns you; click “Continue.” The query name turns italic, and it will take up no space in the file.
Also check the type of each column. It shows in the column header, to the left of its name. ABC means text, 123 a whole number, a small calendar a date. Power Query guesses the type on import, and sometimes gets it wrong. For example, the Date column may show numbers, like 45306 for 1/15/2024.
In that case, click the type icon and choose “Date.” If a conversion already exists, Power Query asks whether to replace it. Answer “Replace current.”
Do this in “Flat Sales.” The tables that start from it will inherit the right date.
Don’t delete any column in “Flat Sales.” The other queries start from its result. A column deleted there disappears for them too, and their steps that used it fail with an error.
01.6.4Create the dimension tables
To create Customers, right-click “Flat Sales,” then choose “Reference.” The new query starts from the result of “Flat Sales.” Rename it, keep only the customer columns, then remove the duplicates.
Create Products the same way, with “Product Code,” “Brand,” “Model” and “Category.” 4 rows remain, one per product.
In both tables, remove the duplicates on the code column, Customer ID for Customers and Product Code for Products. Two rows with the same code describe the same customer, or the same product. Yet the code serves as the of the table, and a primary key allows no duplicates. With a customer listed twice, Power BI could not link Customers to Sales with a one-to-many relationship.
01.6.5Slim down the fact table
One last “Reference” of “Flat Sales” becomes “Sales,” the fact table. Keep the sale ID, the date, the two codes and the numbers in it. The descriptions now live in Customers and Products.
Close & Apply loads Customers, Products and Sales into the model. “Flat Sales” stays out, since its load is disabled.
01.6.6Create your date table
Your tables are in the model. They still lack the date table, the one the time intelligence functions need. Create it now, in DAX.
In Table view, click New table, then type this formula and confirm with the check mark:
Calendar = CALENDARAUTO()
CALENDARAUTO finds the first and the last date in your model, and produces every day of the years they cover, here 2024 and 2025, which makes 731 rows.
Then tell Power BI that Calendar is your date table. In Model view, click at the top right of the Calendar table, then Mark as date table.
A window opens. Turn on the toggle, then choose the Date column. Power BI checks that each date appears only once and that no day is missing, then shows “Validated successfully.” Click Save.
Without “Validated successfully,” the column has a duplicate date or a missing day, and Power BI refuses to save it. With CALENDARAUTO, this doesn’t happen.
If you are more at ease in Excel, a few formulas can do the same split. Another lesson shows how.
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
In the “Customers” query, created with “Reference,” you keep “Customer ID,” “Name,” “Type” and “City,” then remove the duplicates on “Customer ID.” How many rows are left?
Question 2
To slim things down, you delete the Brand column in the “Flat Sales” query. What happens to the “Products” query, created with “Reference”?
Question 3
The next month, a new extract arrives, with 15 sales. What do you need to redo in Power Query to get Sales, Customers and Products?
- Keep the flat table intact in a source query, and disable its load. Check the type of the Date column there.
- Each table starts from this query with “Reference.” Customers and Products keep only their own columns, without duplicates. Sales keeps the sale ID, the date, the two codes and the numbers.
- Power Query replays your steps at each refresh. The split is done only once.
- Create Calendar with CALENDARAUTO, then mark it as a date table.