-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Power Query Cookbook
By :

Power Query users (when they start to use and explore the tool) usually start by connecting to a local file. They can see from the start that the main file types are supported and each of these will display data in a readable format.
In this recipe, we will connect to an Excel file and see how to navigate and expand the different sheets and how to connect to cut-off text/CSV files.
Figure 2.5 – Get Data File section
In this recipe, in order to test different types of file connectors, you need to download the following files in a local folder:
AdventureWorksSales
Excel fileFactResellerSales
CSV fileIn this example, we will refer to the C:\Data
folder.
Once you have opened your Power BI Desktop application, perform the following steps:
Figure 2.6 – Get data Excel connector
Figure 2.7 – Local folder view
Figure 2.8 – Excel data preview
Each item in the left pane matches an item in the Excel file. By only clicking on an item, you will see a preview of the data in the right pane and if you check it, you will include the item in the Power Query view. Therefore, flag the following queries: Customer, Date, and Product. Click on Transform Data.
Figure 2.9 – Power Query interface
Let's add a connection to a CSV file:
Figure 2.10 – Get data Text/CSV connector
FactResellerSales
CSV file. Select it and open it as in the previous section with the Excel file. The following window will pop up:Figure 2.11 – CSV data preview
For each file, you can define the following:
a) File Origin: Define the file encoding (in this case, we will keep the default Unicode UTF-8).
Figure 2.12 – Define the file encoding
b) Delimiter: Select the right delimiter (in this case, we will keep the default Comma):
Figure 2.13 – Define the delimiter
c.) Data Type Detection: This will refer to the first applied step in Power Query when it detects data types for each column (in this case, we will detect data types based on the first 200 rows):
Figure 2.14 – Define Data Type Detection
Figure 2.15 – Extract Table Using Examples button
The following section will appear:
Figure 2.16 – Extract Table Using Examples interface
676
, which is the first ResellerKey value you see in the example, and click on Enter:Figure 2.17 – Insert values example
Figure 2.18 – Insert value detail example (left) and fill in missing or wrong values (right)
Figure 2.19 – Create a second column example
Figure 2.20 – Power Query interface
In the APPLIED STEPS section, you will see some activities mapped as a result of Extract Table Using Examples performed previously.
Power Query, thanks to these file connectors, allows users to connect to single files and perform some pre-transformation tasks allowing them to load just relevant data in the usual interface. However, these connectors – Excel, TXT/CSV, and also Parquet file are related to single files. We will see in the following recipe how to connect to multiple files.