Get and transform data in Power BI

Every report starts with data. Power BI fetches it from Excel, CSV, databases and many other sources. Before it reaches the model, you tidy it up in Power Query: headers, data types, unwanted rows.

In short: Home, Get data, pick the source, tick the table in the Navigator, then Transform Data. In the Power Query Editor every click becomes a step. Close & Apply loads the result into the model.

Prerequisites: Power BI basics.

Try it now

A CSV file is loaded, but still raw. At the top you see the file, below it the Power Query Editor with preview, commands and applied steps. Clicking a column header selects the column.

Task The CSV file with the orders is loaded, but Power Query did not detect the headers (Column1 to Column4), and Amount and Quantity are text. Turn the first row into headers and change the data type of Amount and Quantity to Whole Number.

ABCD
1 OrderID Region Amount Quantity
2 1 South 1798 2
3 2 West 1145 5
4 3 East 596 4
5 5 West 3596 4
6 6 East 745 5
7 7 North 196 4

Get data

On the ribbon under Home you find Get data. The most common sources have their own buttons next to it, such as Excel workbook. After choosing the file, the Navigator opens: it lists the tables and sheets in the file. You tick what you need and then have two options:

  • Load takes the data as it is, straight into the model.
  • Transform Data opens the Power Query Editor first. That is almost always the better choice, because hardly any file is clean.

The Power Query Editor

Power Query shows a preview of the data. Every command you run goes into Applied Steps on the right. The original file stays unchanged; Power BI only remembers the steps and applies them again on every refresh. When next month's file arrives with more rows, it is prepared the same way.

The most important commands to start with:

CommandWhat for
Use First Row as Headerswhen the columns are called Column1, Column2 …
Data TypeText, Whole Number, Decimal Number, Date. Only numbers can be summed in the report.
Filter Rowsremove cancellations, blank rows or test data
Remove Columnswhatever nobody needs in the report only makes the model bigger

Power Query in Power BI is the same tool as in Excel. If you already know it from there, you will feel at home straight away.

One more exercise: filter out cancellations

The sales report should only contain delivered orders. Filter out the cancelled ones, then remove the column that now holds only one value.

Task Cancelled orders do not belong in the sales report. Keep only the rows whose Status is not Cancelled, then remove the Status column.

ABC
1 OrderID Status Amount
2 1 Delivered 1798
3 2 Cancelled 1145
4 3 Delivered 596
5 4 Delivered 1145
6 5 Cancelled 3596
7 6 Delivered 745
8 7 Delivered 196

In real Power BI: load an Excel file

  1. Home, Excel workbook (or Get data, Excel workbook), choose the file.
  2. In the Navigator, tick the table or sheet. A preview appears on the right.
  3. Click Transform Data. The Power Query Editor opens in its own window.
  4. Tidy up: headers, data types, filters. Every step is listed on the right and can be deleted there.
  5. Close & Apply (top left under Home). The table then appears in the Data pane.

Common mistakes

Numbers stay text

If a number is stored as text in the model, a visual only offers Count for that column, not Sum. In the editor you recognise text by the ABC icon in the column header. Change the data type before you close.

Data type before headers

As long as the first row is still data, it holds the word "Amount". If you convert the column to numbers first, that row becomes an error. So headers first, then data types.

Filtering in the report instead of Power Query

Whatever never belongs in the report, filter out in Power Query. A filter in the report leaves the rows in the model, and every new visual would have to repeat it.

Frequently asked questions

Which data sources can Power BI load?

A great many: Excel, CSV and text, folders with many files, SQL Server and other databases, SharePoint lists, web pages and many online services. The list is under Get data, More.

What happens on refresh?

Power BI reads the source again and reapplies every applied step. That is why it pays to tidy data in Power Query rather than by hand in the source file.

Where can I learn more Power Query?

Level 2 of this course covers Power Query in depth: splitting columns, merging and appending queries, unpivoting, grouping.

Learn this next: create a visual

Put fields into the right wells: sum, average and count.

Create a visual

Write to us

Choose language

Select your preferred language