You are on page 1of 5

Combining multiple les 169

Figure 5.27 – Null values for non-matching columns


You can append more than two tables and apply the same logic to a wider number
of queries.

Combining multiple �les


While working with your data, you may need to automatically combine multiple les. You
could use the append transformation method, but if you imagine a use case where there
are les loaded into a folder with a de ned frequency and you need to see the new data
coming at each refresh, it is clear that an alternative method is needed. In this recipe, you
will see how to connect and combine multiple les with just a few clicks, regardless of how
many there are in the folder.
170 Combining Queries for E ciency

Getting ready
For this recipe, to test di erent types of le connectors, you need to download
a CSVFiles folder containing CSV les, as shown in the following screenshot:

Figure 5.28 – Local folder with CSV les


In this example, I will refer to the following path: C:\Data\CSVFiles.

How to do it…
Open the Power BI Desktop application to perform the following steps:

1. Go to Get Data, then click on the Folder connector. You can directly enter your
folder path or click on Browse and select the folder from the usual browsing section
of your machine. en, click on OK.
2. You will see the following window with a list of les contained in the folder:
Combining multiple les 171

Figure 5.29 – How les from the folder are displayed


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

Figure 5.30 – List of les in Power Query view


172 Combining Queries for E ciency

4. Click on the Combine icon, which you will nd in the le corner of the Content
column, as shown in the following screenshot:

Figure 5.31 – Combine icon


5. e Combine Files window will pop up. From here, you can de ne which le to
use in the Sample File eld and de ne the File Origin, Delimiter, and Data Type
Detection elds. Leave the detected values you see for each eld and click on OK,
as seen in the following screenshot:

Figure 5.32 – Combine Files window


Using the Query Dependencies view 173

6. You can see that all data from all les is collected in one query:

Figure 5.33 – Combine Files output


With the Combine transformation method, there will be a set of transformations that are
automatically generated by the system. ese include the de nition of a sample le and
a function that iterates over all the les in the folder and then expands and appends them.
Users can customize this generated function and adapt it to their custom use cases. An
example will be explored in Chapter 8, Adding Value to Your Data.

Using the Query Dependencies view


Once you become con dent using Power Query, you can start adding a higher number of
queries, combining them, and applying complex transformation logic. You can o en get lost
in terms of how queries were built and merged and you may need a view that allows you to
map data sources and queries. In this recipe, we will see how the Query Dependencies view
will allow us to quickly see what is going on in that Power Query session.

Getting ready
In this recipe, you will need to connect to Azure SQL Database with AdventureWorks
data. You need to have access to a running database.

You might also like