You are on page 1of 7

Creating a query from a folder 49

In the APPLIED STEPS section, you will see some activities mapped as a result of Extract
Table Using Examples performed previously.

R LW RU
Power Query, thanks to these le connectors, allows users to connect to single les 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 le are
related to single les. We will see in the following recipe how to connect to multiple les.

UHDWLQJ D TXHU IURP D IROGHU


A er playing with single les as the previous recipe showed, you need to load more les as
their analytical workloads grow. If les are organized in folders, users can leverage a folder
connector to load multiple les. Imagine having a collection of CSV les where each
contains sales data for a speci c day. What if we want to connect to a folder that contains
these les, and we want to load them in Power Query as a single table? e way to go is to
leverage the folder connector.
In this recipe, we will see how to connect to a folder with sales data in CSV format and a
folder with nance data in Excel format (each le contains multiple sheets).

HWWLQJ UHDG
In this recipe, in order to test di erent types of le connectors, you need to download the
following folders, each containing a set of les:

• e CSVFiles folder containing the following CSV les:

Figure 2.21 – Local folder with CSV les


50 Connecting to Fetch Data

• e ExcelFiles folder containing the following Excel les:

Figure 2.22 – Local folder with Excel les


In this example, I will refer to the following paths:
a) C:\Data\ExcelFiles
b) C:\Data\CSVFiles
You can nd the folders and the related les referred to in this chapter at https://
github.com/PacktPublishing/Power-Query-Cookbook/tree/main/
Chapter02/ExcelFiles and https://github.com/PacktPublishing/
Power-Query-Cookbook/tree/main/Chapter02/CSVFiles.

R WR GR LW
Open the Power BI Desktop application and perform the following steps:

1. Go to Get data, click on Folder, and the following window will pop up. You can
directly enter your folder path or click on Browse… and select it from the usual
browsing section of your machine:

Figure 2.23 – Folder connector


Creating a query from a folder 51

2. Once you click on OK, you will see the following section with a list of les
contained in the folder:

Figure 2.24 – How les from the folder are displayed


At the bottom right, you can see some actions to perform:
a) Combine & Transform Data: You can combine data by appending existing data
at this phase and open Power Query.
b) Combine & Load: You can append tables, load them, and start creating reports
or analyzing data with Excel.
c) Load: Load this list into the Power BI dataset as it is.
d) Transform Data: is opens the Power Query interface and allows you to do
custom transformations.
52 Connecting to Fetch Data

3. Click on Transform Data and you will see the following columns:

Figure 2.25 – List of les in the Power Query view


From here, you can do one of these actions:
a) Expand a single CSV by clicking on Binary in the Content column:

Figure 2.26 – Expanded table


Creating a query from a folder 53

b) Expand the Attributes column with some relevant information:

Figure 2.27 – Expand the Attributes column


c) Combine les by clicking on the icon on the right, which means Combine:

Figure 2.28 – e Combine icon on the Content column


Data combination is a concept that will be widely explored in Chapter 5, Combining
Queries for E ciency.
54 Connecting to Fetch Data

Now we will repeat the same steps but with the other folder containing Excel les:

1. e view that opens is the following:

Figure 2.29 – List of Excel les in the Power Query interface


It is very similar to the one we saw previously because you can perform the
following actions:
a) If you click on Binary in row 1, you will end up with a table with a list of the
sheets contained in the Excel le FinanceData-OnlineChannel. If you click
on Table in row 1, you will expand the sheet Sales:

Figure 2.30 – First level of the expanded table


Creating a query from a folder 55

b) If you click on Combine, the following window will pop up:

Figure 2.31 – Table preview during the Combine step


is built-in combine function will allow you to append the Sales sheets from three
di erent Excel les. is topic will be widely explored in Chapter 5, Combining Queries
for E ciency.

R LW RU
e idea of this recipe was to show you the potential of the folder connector because o en
users end up connecting multiple times to single les and then perform an append step.
is takes time, and it is di cult to maintain when the number of les becomes bigger.
e folder connector allows you to refresh your data and perform all Power Query
operations automatically. If you add a le in your folder and click on refresh, you will end
up with a nal table enriched with data coming from this last le.

You might also like